TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
Reply
Answers (
21
)
C# SQL Connection class
Dynamically change datagridview combo box values