The following code (exactly the same) is running fine on another project.
private void AddComboBoxCells()
{
DataGridViewComboBoxCell dgvcell;
_query = "select ProductName from Product";
com = new SqlCommand(_query, con);
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
dgvcell = new DataGridViewComboBoxCell();
dataGridView1[1, i] = dgvcell;
myrdr = com.ExecuteReader();
while (myrdr.Read())
{
dgvcell.Items.Add(myrdr.GetValue(0));
}
myrdr.Close();
}
}
On this project currently i am trying to run this same code but i am getting following error at runtime:

What i am doing is i am pulling records i.e. product names and populating it in the second column of the datagridviewcomboboxcell.
EDIT
private void btnAdd_Click(object sender, EventArgs e)
{
DataRow dtr = tblOrders.NewRow();
tblOrders.Rows.Add(dtr);
DataGridViewComboBoxCell dgvcell;
_query = "select * from Product";
com = new SqlCommand(_query, con);
dgvcell = new DataGridViewComboBoxCell();
dataGridView1[1, dataGridView1 .Rows.Count -2 ] = dgvcell;
myrdr = com.ExecuteReader();
while (myrdr.Read())
{
dgvcell.Items.Add(myrdr[0]);
}
myrdr.Close();
}
This Add button Code works hence the Data coming in is valid for sure. Please assist.
First of all you may want to attach a handler to the DataError event of the DataGridView control to get access to more information about the error you are getting.
Second, the obvious things to check are the data context that you’re using in the second project. It seems very likely that it is not a programming error necessarily but more like an issue that is related to the underlying data that you are querying and/or doing data binding against.
You may want to investigate the type of data and the values that are returned by your query:
select ProductName from Product.Look at
myrdr.getValue(0)– rewrite the linedgvcell.Items.Add(myrdr.GetValue(0));like this:EDIT
To answer your question regarding how to handle the DataError event, all you need to do is simply attach a handler to the event member of your ‘dataGridView1’ object (if you don’t know what events are, or how to attach handlers to events in C# then I suggest you do some reading about that online – there are tons of resources everywhere)