473,396 Members | 1,738 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,396 software developers and data experts.

Handle NULL in reader?

qqq
I have the following code to read from an Access db with
Provider=Microsoft.Jet.OLEDB.4.0 (code simplified here):

Dim cmd As New System.Data.OleDb.OleDbCommand("Select numbookings from
TblEvents where Entid=33", conn)
Dim Reader As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
If Reader.Read() Then
x=Reader.GetInt16(0).ToString
End If

This fails if the value for numbookings is NULL with the following error:
Run-time exception thrown : System.InvalidOperationException - The provider
could not determine the Int16 value. For example, the row was just created,
the default for the Int16 column was not available, and the consumer had not
yet set a new Int16 value.

How can I detect the NULL value? I've played with IsDbNull etc, but can't
get it to work. I also tried using the Access NZ function in the SQL
command, but get 'unrecognized function'.
Thanks for any help,
Paul.
Nov 21 '05 #1
3 9009
"qqq" <qq*@qqq.com> wrote in news:em**************@TK2MSFTNGP10.phx.gbl:
How can I detect the NULL value?


Use System.DBNull.Value

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
qqq
Care to elaborate a little bit (e.g. show me one line of code)? I tried to
get this to work and couldn't.

Thanks,

Paul.
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"qqq" <qq*@qqq.com> wrote in news:em**************@TK2MSFTNGP10.phx.gbl:
How can I detect the NULL value?


Use System.DBNull.Value

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #3
qqq,
As Lucas suggested use System.DBNull' to see if the first field is a
database NULL or not.

The easiest way to check for System.DBNull is to use the
OleDbDataReader.IsDBNull method.

If Reader.Read() Then
If Not Reader.IsDBNull(0) Then
x = Reader.GetInt16(0).ToString
End If
End If

Hope this helps
Jay

"qqq" <qq*@qqq.com> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
I have the following code to read from an Access db with
Provider=Microsoft.Jet.OLEDB.4.0 (code simplified here):

Dim cmd As New System.Data.OleDb.OleDbCommand("Select numbookings from
TblEvents where Entid=33", conn)
Dim Reader As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
If Reader.Read() Then
x=Reader.GetInt16(0).ToString
End If

This fails if the value for numbookings is NULL with the following error:
Run-time exception thrown : System.InvalidOperationException - The provider could not determine the Int16 value. For example, the row was just created, the default for the Int16 column was not available, and the consumer had not yet set a new Int16 value.

How can I detect the NULL value? I've played with IsDbNull etc, but can't
get it to work. I also tried using the Access NZ function in the SQL
command, but get 'unrecognized function'.
Thanks for any help,
Paul.

Nov 21 '05 #4

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

Similar topics

11
by: eddy de boer | last post by:
Hello, in my aspx page I have the followong code: <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> .... <%# Server.HtmlDecode((string)DataBinder.Eval(Container.DataItem,"tekst"))...
6
by: Dean Slindee | last post by:
I am looking for the "right" way to handle inserting and presenting null date values. Public Const c_NullDate As Date = #12:00:00 AM# If I set the value of a date variable in an SQL Server insert...
0
by: Jason Coyne | last post by:
Here is another programming blog entry. Sorry for the normal friends :) I recently ran into a problem with a web service I was trying to call from c# where the web service returned null dates...
3
by: psycho | last post by:
how should i hanle null values returned by the datareader i am using OleDbDataReader for accessing access database.
1
by: hunki | last post by:
We recently moved from Websphere to JBOSS, we know WebSphere automatically respawned connections when they were NULL but how to handle this in JBOSS. Thanks, hunki
5
by: tonialbrown | last post by:
I have some code that updates a record's fields based on a selection from a list box (lstDelFrom). The user selects the record from the list box & it copies it into the fields , , etc. My...
5
by: dhanashivam | last post by:
Hi all, In my table there is a varchar column having NULL and string names. while i am running select on this table the NULL values are not returned. the statement returns only non null...
1
by: apache626 | last post by:
I really need help with this one. I am using a script task to write data pulled from a MS SQL DB to a fixed width file. The script takes the ItemArray and writes the value of the column to the file...
1
by: NareshN | last post by:
Hi, I am using this stored procedure with pivot.If i dont have data i am getting null with this stored procedure.Can u tell me how to handle null.below query is pivot. I am using like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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...

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.