I tried the following code to enter value in a cell to get the value from data table. But I get an error. Below is error:
The following exception occurred in the DataGridView:
System.Exception: 0.91 is not a valid value for Int32. —>
I HAVE NO IDEA HOW TO ELIMINATE THIS ERROR. NEED HELP.
EDIT:-
private void DataGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
{if (DataGrid.CurrentCell.ColumnIndex == 6)
{
string getprice = "SELECT " + DataGrid.SelectedRows[0].Cells[3].Value.ToString() + " FROM " +
"" + DataGrid.SelectedRows[0].Cells[2].Value.ToString() + "_Mstr " +
"WHERE Size1 = '" + DataGrid.SelectedRows[0].Cells[4].Value.ToString() + "'";
DataTable dt = globalData.q.select(getprice);
double check;
if (double.TryParse(dt.Rows[0][0].ToString(), out check))
{
DataGrid.SelectedRows[0].Cells[6].Value = dt.Rows[0][0].ToString().Trim();
}
}
}
Probably your SQL is a double while you expect an int.
Either change the data type or force the conversion (I.e. with Convert.ToInt32(xxx) instead of double.Parse)