WallyAnchor
Programmer
Hi.
I'm having troubles understanding what the problem is with this. In my application I'm trying to parse & insert a (valid) string into a column/row in a datatable.
Here's a boiled down example:
Dim dt As DataTable = New DataTable("dt")
dt.Columns.Add("dbl", Type.GetType("System.Double"))
Dim r As DataRow = dt.NewRow
Decimal.TryParse("4", r("dbl")) '<---- gives error "Conversion from type 'DBNull' to type 'Decimal' is not valid."
If I 'initialise' r("dbl") = 0 or something first, it appears to work here, although that causes other issues in my actual application. And DBNull could be valid anyway, if I'm not populating that column for a particular row.
So I'm very confused as to what the problem is here? Can somebody please point out what's wrong with my example?
Cheers
Wally
I'm having troubles understanding what the problem is with this. In my application I'm trying to parse & insert a (valid) string into a column/row in a datatable.
Here's a boiled down example:
Dim dt As DataTable = New DataTable("dt")
dt.Columns.Add("dbl", Type.GetType("System.Double"))
Dim r As DataRow = dt.NewRow
Decimal.TryParse("4", r("dbl")) '<---- gives error "Conversion from type 'DBNull' to type 'Decimal' is not valid."
If I 'initialise' r("dbl") = 0 or something first, it appears to work here, although that causes other issues in my actual application. And DBNull could be valid anyway, if I'm not populating that column for a particular row.
So I'm very confused as to what the problem is here? Can somebody please point out what's wrong with my example?
Cheers
Wally