Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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.
- /*
- CREATE PROCEDURE dbo.IrCQUser_Login
- (
- @Username nvarchar(MAX),
- @Password nvarchar(MAX)
- )
- AS BEGIN
- SELECT UserID,
- RetryWait,
- Username,
- Password
- FROM IrCQUser
- WHERE (Username = @Username) AND (Password = @Password);
- END
- */
- /*----------------------*/
- // 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.
- public bool Load(SqlConnection SqlConnection, string Username, string Password)
- {
- SqlCommand sqlCommand = new SqlCommand("dbo.IrCQUser_Login", SqlConnection);
- SqlDataReader sqlReader;
- bool success;
- sqlCommand.CommandType = CommandType.StoredProcedure;
- sqlCommand.Parameters.Add("Username", SqlDbType.NVarChar).Value = Username;
- sqlCommand.Parameters.Add("Password", SqlDbType.NVarChar).Value = Password;
- sqlReader = sqlCommand.ExecuteReader();
- success = Load(sqlReader) && intUserID != 0;
- sqlReader.Close();
- return success;
- }
- public bool Load(SqlDataReader SqlReader)
- {
- if (!SqlReader.Read()) { return false; }
- intUserID = (int)SqlReader["UserID"];
- intRetryWait = (int)SqlReader["RetryWait"];
- strUsername = (string)SqlReader["Username"];
- strPassword = (string)SqlReader["Password"];
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement