Last post Apr 16, 2020 07:05 PM by rkrex
Apr 16, 2020 05:16 PM|rkrex|LINK
I am using the sqldatareader in MVC to return records and populate a model for my view. For some reason my code does not execute the while loop. I was wondering if someone could help me with a problem they see maybe in how I have structured the connection,
command, and reader object and why the reader is not returning any records. Thanks !!!
public ActionResult ShowSSN(ShowSSN.Models.ShowSSNModel model)
string conn = "";
conn = ConfigurationManager.ConnectionStrings["Dalton"].ToString();
using (SqlConnection sqlConnection = new SqlConnection(conn))
using (SqlCommand sqlCommand = new SqlCommand("[dbo].[spGetSSN]", sqlConnection))
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add(new SqlParameter("@ssn", model.SSN));
//using (SqlDataReader sqlDataReader = new sqlCommand.ExecuteReader();
using (SqlDataReader rdr = sqlCommand.ExecuteReader())
var value= Convert.ToInt32(rdr["DataBaseName"]);
//var student = new List<SSNs>();
// student. = rdr["numberofssn"];
////student.LastName = rdr["LastName"];
////student.Class = rdr["Class"];
Apr 16, 2020 06:48 PM|DA924|LINK
Bad parm maybe. Did you take the parm after stopping on a debug breakpoint and used it in executing the sproc using SSMS?
Apr 16, 2020 07:05 PM|rkrex|LINK
Thanks for your help !!! I apologize for the oversight. Yes, you are correct the parameter value was truncated and I am not sending the entire string. Let me make the changes and see if it will fix the problem. Thank You ver much.