|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Casting a DBNullI'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 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
Web activation
Using Classes as List Items date/time fields Conditional statements SystemIndexOutOfRangeException error CheckForIllegalCrossThreadCalls ? using Generics dynamically (?) File upload to website and rezise at the same time ADO.NET 2.0 TableAdapter Configuration Wizard FileSystemWatcher UNC Path Invalid |
|||||||||||||||||||||||