Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
21
Answers
"The SelectCommand property has not been initialized before calling 'Fill'.
Avuya Mxoli
13y
7.4k
1
Reply
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
Post
Reset
Cancel
Answers (
21
)
Next Recommended Forum
C# SQL Connection class
Dynamically change datagridview combo box values