473,413 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Casting a DBNull

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

Jan 25 '06 #1
1 1271
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
Jan 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: djc | last post by:
I have typically always used one of the VB CType functions (not CType itself but CInt, CString, etc...) to cast/convert an input value to its proper type before passing it as a parameter to a SQL...
4
by: Tina | last post by:
I have instantiated an insertRow for a dataset. I now want to make the GLCode DBNull. I have tried: insertRow.GLCode = Convert.dbnull insertRow.GLCode = Convert.dbnull(insertRow.GLCode) and...
8
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations...
10
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
10
by: Tyler Durden | last post by:
Hi, I have this annoying problem with a cast failing from a DAL that was created in 1.1 that I have included in a 2.0 app. Every stored proc in our system uses an integer parameter to return...
6
by: Mike | last post by:
When using a DataReader to return records from a SQL server, I'm having a problem with the following code (abbreviated) int ID = 0; ID = (int)dr; will work if the user_id column is an int...
2
by: .Net Sports | last post by:
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...
6
by: cj | last post by:
in the command window I get: ? result {System.DBNull} : {System.DBNull} I need to check for this in code. I then tested in the command window if result = system.DBNull 'DBNull' is a type...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.