21
Answers

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

Avuya Mxoli

Avuya Mxoli

13y
7.4k
1
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)