I want to catch on -1, 0, 1 values returning from the SQL Server stored procedure in C#.
SQL Server:
IF EXISTS(SELECT * FROM _Users WHERE UserName = @UserName AND [Password] != @Password)
BEGIN
RETURN -1
END
IF EXISTS(SELECT * FROM _Users WHERE UserName != @UserName AND [Password] != @Password)
BEGIN
RETURN 0
END
IF EXISTS(SELECT * FROM _Users WHERE UserName = @UserName AND [Password]= @Password)
BEGIN
RETURN 1
END
C#
Are we able to change the returning value of the code below just by making as I want to?
public User getUser(string name, string password)
{
User user = null;
using (var connection = Database.GetConnection())
{
var command = new SqlCommand("SP_GetUser @UserName, @Password", connection);
command.Parameters.Add(new SqlParameter("UserName", name));
command.Parameters.Add(new SqlParameter("Password", password));
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
user = new User();
user.UserId = Convert.ToInt32(reader["UserId"]);
user.userName = Convert.ToString(reader["UserName"]);
user.password = Convert.ToString(reader["Password"]);
}
}
connection.Close();
}
return user; // I want to return -1, 0, 1
}