Using Output parameter in ASP .Net Framework 3.5
-
Folks, I'm calling a stored proc from the built in login control in .Net. The stored proc is set up in such a way that it requires 4 parameters and one of them is a output parameter. I have a feeling I'm doing something wrong when I set up the output parameter in my code to be passed to the stored proc because the DBA (can see in his profiler my first 3 parameters coming in twice and that's what's causing problems. Here's the code I'm using to set up the output parameter. Can someone please verify it for me :)
SqlCommand cmd = new SqlCommand("sp_ValidateUser", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@varUserName", UserName);
cmd.Parameters.AddWithValue("@varUserPwd", Password);
cmd.Parameters.AddWithValue("@varCaseNumber", this.txtBoxCaseNumber.Text);SqlParameter outputParam = new SqlParameter("@varISValid", SqlDbType.SmallInt); outputParam.Direction = ParameterDirection.Output; cmd.Parameters.Add(outputParam); SqlDataReader Dr; Dr = cmd.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr\["UserName"\].ToString()) & (Password == Dr\["UserPwd"\].ToString())) { boolReturnValue = true; } Dr.Close(); return boolReturnValue; } return boolReturnValue; }
Thanks Tina
-
Folks, I'm calling a stored proc from the built in login control in .Net. The stored proc is set up in such a way that it requires 4 parameters and one of them is a output parameter. I have a feeling I'm doing something wrong when I set up the output parameter in my code to be passed to the stored proc because the DBA (can see in his profiler my first 3 parameters coming in twice and that's what's causing problems. Here's the code I'm using to set up the output parameter. Can someone please verify it for me :)
SqlCommand cmd = new SqlCommand("sp_ValidateUser", conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@varUserName", UserName);
cmd.Parameters.AddWithValue("@varUserPwd", Password);
cmd.Parameters.AddWithValue("@varCaseNumber", this.txtBoxCaseNumber.Text);SqlParameter outputParam = new SqlParameter("@varISValid", SqlDbType.SmallInt); outputParam.Direction = ParameterDirection.Output; cmd.Parameters.Add(outputParam); SqlDataReader Dr; Dr = cmd.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr\["UserName"\].ToString()) & (Password == Dr\["UserPwd"\].ToString())) { boolReturnValue = true; } Dr.Close(); return boolReturnValue; } return boolReturnValue; }
Thanks Tina