Avuya Mxoli

Avuya Mxoli

  • NA
  • 236
  • 208.7k

Invalid attempt to read when no data is present

Oct 10 2011 6:16 AM
Hi,
I am working on a project and I am having trouble with this error(see subject line). This happens when I try to select a country from a combo box and what should happen is that when I do this there is a stored procedure that is called in my sql database which reads form a table that has data but then I get this error which suggests otherwise,any ideas?Thnks
Here is where the error occurs:
 using (SqlConnection conn = new SqlConnection(ConnString))
            {
                SqlCommand cmd = new SqlCommand("GetGameForCountry", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Country", match);
          //game is a class in my program  Game aGame;
                try
                {
                    conn.Open();
                }
                catch
                {
                }
                SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);
                reader.Read();
   // error here>>>    aGame = new Game(reader["ID"].ToString(), reader["Location"].ToString(), reader["DateTime"].ToString());
                reader.Close();
                }
                return aGame;

Answers (27)