Home All Groups Group Topic Archive Search About
Author
25 Jan 2006 7:01 PM
.Net Sports
I'm trying to match fields from XML feed to a datarow, but I get a
"System.InvalidCastException: Object cannot be cast from DBNull to
other types" error at the PkgAmount line. This code was converted from
original C# code, so I'm wondering if it has something to do with C#'s
strict datatype criteria (even tho this is in vb.net), or I need to do
something extra around the
FormatAmount(Convert.ToSingle(drwData("PkgAmount"))) ...
'''''''''''''''''
Dim drwData As DataRow
            For Each drwData In dtaData.Rows
Dim SID As String =  "SID=" & Convert.ToString(drwData("ID")) & "&"
Dim PurchaseTypeID As String =  Convert.ToString(drwData("PurchaseID"))
Dim PkgAmount As String =
FormatAmount(Convert.ToSingle(drwData("PkgAmount")))
'''''''''''''''''''''
TIA
netsports

Author
25 Jan 2006 7:16 PM
Cor Ligthert [MVP]
Hi

Why not write it in VB.Net code (However, you can in C# as well not use a
string as a single)

Altough it is a little bit strange code, alone the last line will fill the
items which are inside the method so those can never be used.

Dim drwData As DataRow
For Each drwData In dtaData.Rows
Dim SID As String =  SID=" & drwData("ID").ToString & "&"
Dim PurchaseTypeID As String =  drwData("PurchaseID").ToString
Dim PkgAmount As Single = Csng(drwData("PkgAmount"))
''Or just as the other strings,

I hope this helps,

Cor