User-305496339 posted
Hi Friends,
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();
{
sqlConnection.Open();
using (SqlDataReader rdr = sqlCommand.ExecuteReader())
{
while (rdr.Read())
{
var value= Convert.ToInt32(rdr["DataBaseName"]);
//var student = new List<SSNs>();
// student. = rdr["numberofssn"];
////student.LastName = rdr["LastName"];
////student.Class = rdr["Class"];
//model.Add(student);
}
}
}
}