I have a datagrid in which i have combobox in a column. On a particular event i want to populate the combo box with result of the query. I wrote this code
string materialQuery = "Select material_name from tbl_material_master where material_id =" + int.Parse(mat_id);
cmd1 = new SqlCommand(materialQuery, con);
sdr = cmd1.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
materialName = sdr["material_name"].ToString();
grdPurchase.Rows[0].Cells[2] = materialName.ToString();
}
}
But it gives error
How do i fix this?
Assuming no data errors, try adding the items to the
Itemscollection of the ComboBox: