NullReferenceException: Object reference not set to an instance of an object. WebApplication1.Controllers.LabsDal.GetDefinition(string connectionString, string key) in LabsDal.cs on line while (rdr2.Read())
conn.Open();
using (var cmd = new SqlCommand("Lab_GetDefinitionList", conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@key", key);
SqlDataReader rdr2 = cmd.ExecuteReader(System.Data.CommandBehavior.SingleResult);
while (rdr2.Read()) // <---- ERROR HERE
{
result.Elements.Add(rdr2.GetString(0));
}
}
I have tried many variation and have made no progress. Else where the equivalent code is working fine.