How to insert null value for numeric field of a datatable in c#?
Posted
by Pandiya Chendur
on Stack Overflow
See other posts from Stack Overflow
or by Pandiya Chendur
Published on 2010-05-28T06:12:19Z
Indexed on
2010/05/28
9:32 UTC
Read the original article
Hit count: 213
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...
© Stack Overflow or respective owner