Avuya Mxoli

Avuya Mxoli

  • NA
  • 236
  • 208.7k

"The SelectCommand property has not been initialized before calling 'Fill'.

Oct 13 2011 4:06 AM
Hi,

 I am still struggling with the problem I posted earlier this week about filling my gridview. The same procedure works fine when I execute it in sql but in c# it doesnt fill the grid. I get ths exception error when I do this:
               DataTable dtGames = new DataTable();
               try
                {
               
                  SqlCommand cmd = new SqlCommand("GetGameForCountry '" + game + "'", conn);
                  dbAdapter = new SqlDataAdapter(dbCommand);
                   dbAdapter.Fill(dtGames);
                }
                catch(SqlException sqlex)
                {
                    MessageBox.Show("SQL exception: " + sqlex.Message);
                }
               catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return dtGames;
I then call this in the combobox text changed event like this:


            try
            {
                dgvGame.DataSource = bl.getGameForCountry(cboCountry.SelectedValue.ToString());


            }
            catch (SqlException sqlex)
            {
                MessageBox.Show("SQL exception: " + sqlex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Any ideas why I am getting this error?Thanks

Answers (21)