DataTable C# Empty column type
Posted
by Dested
on Stack Overflow
See other posts from Stack Overflow
or by Dested
Published on 2010-04-26T03:13:59Z
Indexed on
2010/04/26
3:23 UTC
Read the original article
Hit count: 331
I am trying build a DataTable one row at a time using the following code.
foreach (var e in Project.ProjectElements[hi.FakeName].Root.Elements()) {
index = 0;
object[] obj=new object[count];
foreach (var holdingColumn in names) {
string d = e.Attribute(holdingColumn.Key).Value;
obj[index++] = d;
}
dt.Rows.Add(obj);
}
The problem is the DataTable has types tied to the columns. Sometimes im passing null (or an empty string) in that object index and it is telling me that it cant be converted properly to a DateTime (in this case). My question is what should I default this value to, or is there some way to have the DataTable ignore empty values.
© Stack Overflow or respective owner