Consider My dynamically generated datatable contains the following fileds Id,Name,Mob1,Mob2
If my datatable has this it get inserted successfully,
Id Name Mob1 Mob2
1 acp 9994564564 9568848526
But when it is like this it gets failed saying,
Id Name Mob1 Mob2
1 acp 9994564564
The given value of type String from the data source cannot be converted to type decimal of the specified target column.
I generating my datatable by readingt a csv file,
CSVReader reader = new CSVReader(CSVFile.PostedFile.InputStream);
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
foreach (string strHeader in headers)
{
dt.Columns.Add(strHeader);
}
string[] data;
while ((data = reader.GetCSVLine()) != null)
{
dt.Rows.Add(data);
}
Any suggestion how to insert null value for numeric field during BulkCopy in c#...
EDIT:
I tried this dt.Columns["Mob2"].AllowDBNull = true;
but it doesn't seem to work...