-2

[SCHOOL WORK]

I have a stored procedure:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [IO].[usp_selectUser] (@username varchar(50))
AS
BEGIN
    SELECT passwordSalt, hashedPassword
    FROM [IO].[Users]
    WHERE username = @username;
END

And in my C# program I need to get the passwordSalt and the hashedPassword where username matches:

Current C# code:

SqlCommand command = new SqlCommand("[IO].[usp_selectUser]", con);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar)).Value = username;

I've tried some stuff from Google search results, but none of the worked properly. How do I get two individual strings?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • For 2 strings try output parameters. – Dale K May 04 '20 at 08:41
  • 2
    For getting data from SQL Server has loads of tutorials out there - part of doing your homework is doing the research, not getting someone else to solve it for you. – Dale K May 04 '20 at 08:47
  • No need to be rude, i'm not trying to weasle out. I've tried that already, probably wrong since it is not working, here's the code: – Sebastian Marjanović May 04 '20 at 08:48
  • command.Parameters.Add("@passwordSalt", SqlDbType.Int).Direction = ParameterDirection.Output; command.Parameters.Add("@hashedPassword", SqlDbType.Int).Direction = ParameterDirection.Output; command.ExecuteNonQuery(); salt = Convert.ToString(command.Parameters["@passwordSalt"].Value); dbhpass = Convert.ToString(command.Parameters["@hashedPassword"].Value); – Sebastian Marjanović May 04 '20 at 08:49
  • In fact your previous question is virtually identical and has the same answers? – Dale K May 04 '20 at 08:49
  • 1
    Add what you have tried to the question - not a comment. – Dale K May 04 '20 at 08:50
  • My previous question was different, just needed one row, one column where something meets the condition, one string, used info message. – Sebastian Marjanović May 04 '20 at 08:51

1 Answers1

0

A friend solved my problem. The stored procedure didn’t have marked parameters as output.

 USE [TICKETING_DB]
    GO
    /****** Object:  StoredProcedure [IO].[usp_selectUser]    Script Date: 5/4/2020 11:08:10 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [IO].[usp_selectUser] (@username varchar(50), @passwordSalt varchar(50) output, @hashedPassword varchar(100) output)
    AS
    BEGIN
    SELECT @passwordSalt = passwordSalt, @hashedPassword = hashedPassword FROM [IO].[Users]
    WHERE username = @username;

    END
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131