SqlConnection conn = new SqlConnection(connectionString); try { conn.Open(); SqlCommand cmd = new SqlCommand("pr_MySelectProcedure", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; string tempVal = string.Empty; using (SqlDataReader reader = cmd.ExecuteReader()) { // if (reader.HasRows == true) ... passed this test, so continue with other code do { // passes test: if (reader.FieldCount > 0) tempVal = reader[0].ToString(); // exception error here: no data present // also fails with: tempVal = reader["firstcolumnname"].ToString(); } while (reader.Read()); } } catch ...
while(reader.Read()) { tempVal = reader[0].ToString(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)