I'm trying to fetch a record from the database using a stored procedure, but it returns null in SqlDataReader object.
Here is my code:
public Buybest_Liberary.Data.UserManagement getUser(string email)
{
Buybest_Liberary.Data.UserManagement obj = new Buybest_Liberary.Data.UserManagement();
string conString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\ahmadshair\Documents\Buybest.mdf;Integrated Security=True;Connect Timeout=30";
SqlConnection connection = new SqlConnection(conString);
connection.Open();
SqlCommand _cmd = new SqlCommand("getUserRecord", connection);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = email;
SqlDataReader dr = _cmd.ExecuteReader();
if (dr.HasRows)
{
obj.UId = Convert.ToInt32(dr[0]);
obj.Email = dr[1].ToString();
obj.Password = dr[2].ToString();
}
return obj;
}
getUserRecord? Are you really sure it returns some data?