Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

SqlDataReader is not returning any records

$
0
0

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);
                              }
                        }
                    }
                }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>