Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | None | 0 0
  1. // I have the following stored procedure. There is a row that has Username 'foo' and password 'bar'. Executing the stored procedure at shell results in successfully retrieved information.
  2. /*
  3. CREATE PROCEDURE dbo.IrCQUser_Login
  4. (
  5.     @Username   nvarchar(MAX),
  6.     @Password   nvarchar(MAX)
  7. )
  8. AS BEGIN
  9.     SELECT  UserID,
  10.             RetryWait,
  11.             Username,
  12.             Password
  13.     FROM    IrCQUser
  14.     WHERE   (Username = @Username) AND (Password = @Password);
  15. END
  16. */
  17.  
  18. /*----------------------*/
  19. // I have the following C# code, which should execute the stored procedure and retrieve the information from the query. When I use the test values, it fails to retrieve the information.
  20.         public bool Load(SqlConnection SqlConnection, string Username, string Password)
  21.         {
  22.             SqlCommand sqlCommand = new SqlCommand("dbo.IrCQUser_Login", SqlConnection);
  23.             SqlDataReader sqlReader;
  24.             bool success;
  25.             sqlCommand.CommandType = CommandType.StoredProcedure;
  26.             sqlCommand.Parameters.Add("Username", SqlDbType.NVarChar).Value = Username;
  27.             sqlCommand.Parameters.Add("Password", SqlDbType.NVarChar).Value = Password;
  28.             sqlReader = sqlCommand.ExecuteReader();
  29.             success = Load(sqlReader) && intUserID != 0;
  30.             sqlReader.Close();
  31.             return success;
  32.         }
  33.  
  34.         public bool Load(SqlDataReader SqlReader)
  35.         {
  36.             if (!SqlReader.Read()) { return false; }
  37.  
  38.             intUserID = (int)SqlReader["UserID"];
  39.             intRetryWait = (int)SqlReader["RetryWait"];
  40.             strUsername = (string)SqlReader["Username"];
  41.             strPassword = (string)SqlReader["Password"];
  42.  
  43.             return true;
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement