I am trying to import data from an excel file. I get this right and display it in a datagrid view easily. My problem comes in when it comes to the fact that the gallons column should only contain double values above 0 and below 1000; However the excel file contains entries such as f425 or -632 or even null and infinity(or close to it, 1E+12) in the gallons columns. how would i detect these and then change them to null or 0 in the dataset to later be saved to an accdb. I have tried to only detect ones above 1000 and it gets them but the dataset remains unchanged or atleast appears to in the datagirdview.
I have tried casting (long)chart["Gallons"] aswell but obviously it won't cast with my bad data.
Database1DataSet ds = new Database1DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", myConnec); //Where myconnec is connection string to excel file
da.Fill(ds);
label1.Text = ds.Tables[0].TableName;
int i = 0;
foreach (DataRow chart in ds.Tables[0].Rows)
{
if (chart["Gallons"].ToString().CompareTo("1000")<1)
{
chart["Gallons"] = 0;
}
}
dataGridView1.DataSource = ds.Tables[0];