473,473 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Error with DBNull

Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

--

Filipe Cristóvão
Nov 18 '05 #1
2 1482

"Filipe Cristóvão" <fi**************@lizserve.nospam.pt> wrote in message news:eS**************@TK2MSFTNGP12.phx.gbl...
Hi,
I know that this is a newbie's question, but I need to know how i do to know
if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

--

Filipe Cristóvão


Various options:
* You can test against DBNull.Value (if (myDataRow["field"] == DBNull.Value) ... )
* DataRow has an IsNull(..) method to check a specific column in that row
* Don't cast to string, but use the ToString() method, DBNull gives an empty string

Hans Kesting
Nov 18 '05 #2
Tks for the help.
I relly needed to know it.

--

Filipe Cristóvão

"Hans Kesting" <ne***********@spamgourmet.com> escreveu na mensagem
news:%2******************@tk2msftngp13.phx.gbl...

"Filipe Cristóvão" <fi**************@lizserve.nospam.pt> wrote in message news:eS**************@TK2MSFTNGP12.phx.gbl...
Hi,
I know that this is a newbie's question, but I need to know how i do to know if a field in a table is DBNull.
If I try to write (with response.write) the field, it gives me an error:
"Cast from type 'DBNull' to type 'String' is not valid".
Thanks for any help.

--

Filipe Cristóvão


Various options:
* You can test against DBNull.Value (if (myDataRow["field"] ==

DBNull.Value) ... ) * DataRow has an IsNull(..) method to check a specific column in that row
* Don't cast to string, but use the ToString() method, DBNull gives an empty string
Hans Kesting

Nov 18 '05 #3

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

Similar topics

5
by: David Lozzi | last post by:
Howdy, I'm doing some simple database reading and loading severl values into labels for readonly use. Here is my script: Dim selStoreID As String If StoreID.SelectedIndex > -1 Then...
1
by: Child | last post by:
Hi, I am getting the error: "Procedure or function spAddActivity has too many arguments specified. " on a stored procedure insert. I compared the number of parameters in the function and the SP...
1
by: fredda054 | last post by:
Hi everybody ! With help from some nice people here I'm getting close to solve my problem with dbnull values in a repeater. I got it pretty much done, I just ned to fix some syntax. I get a...
8
by: wink martindale | last post by:
Hello, I am writing a vb.net app.Using MySql db with the corelabs connector. I am getting the following error when attempting to read values from a datareader: Cast from type 'DBNull' to type...
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...
3
by: Doug Durrett | last post by:
I'm having an issue and wanted to pass it by everyone to see what you think. Here is my code. //Code Start searchs = new...
9
by: Martin Arvidsson | last post by:
Hi! I have two computed datafields that i am displaying in my windowsform. When i try to update the dataset and commit the transaction. I get an error message telling me that i cant update...
3
by: JFB | last post by:
Hi All, In my function bellow I try to check for a null or empty value coming from my database before I set my phone format. Function Format(ByVal value As Object) 'LabelTest.Text = value If...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.