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

invalid cast prob with oleDBdataReader

....
Dim rdr As OleDbDataReader = cmd.ExecuteReader
If rdr.GetString(1).ToString.Length > 0 Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

The field is in an MS Access table that rdr is reading and
is a text field. I am getting an invalid cast error when
the field is null/empty.

I have tried If Not IsDBNull(rdr.GetString(1).ToString)...

still same problem. How can I trap if the field is null?

Thanks
Nov 21 '05 #1
2 2957
If Not rdr.IsDBNull(1) Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

hope that helps..
Imran.

"James" <an*******@discussions.microsoft.com> wrote in message
news:11****************************@phx.gbl...
...
Dim rdr As OleDbDataReader = cmd.ExecuteReader
If rdr.GetString(1).ToString.Length > 0 Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

The field is in an MS Access table that rdr is reading and
is a text field. I am getting an invalid cast error when
the field is null/empty.

I have tried If Not IsDBNull(rdr.GetString(1).ToString)...

still same problem. How can I trap if the field is null?

Thanks

Nov 21 '05 #2
Yes. Thank you. That did the trick!

-----Original Message-----
If Not rdr.IsDBNull(1) Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

hope that helps..
Imran.

"James" <an*******@discussions.microsoft.com> wrote in messagenews:11****************************@phx.gbl...
...
Dim rdr As OleDbDataReader = cmd.ExecuteReader
If rdr.GetString(1).ToString.Length > 0 Then
Console.WriteLine(rdr.GetString(1).ToString)
End If

The field is in an MS Access table that rdr is reading and is a text field. I am getting an invalid cast error when the field is null/empty.

I have tried If Not IsDBNull(rdr.GetString (1).ToString)...
still same problem. How can I trap if the field is null?
Thanks

.

Nov 21 '05 #3

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

Similar topics

10
by: Dion Heskett | last post by:
I wish to supply the formating as a parameter, I have tried OleDbDataReader but get a null ref. just can't seem to get this to work. I think this has something to do with ExecuteReader. also...
0
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started....
0
by: Steve1 via DotNetMonster.com | last post by:
Hi all, I''ve created an OleDbDataReader that will contain the number of records that the used SQL query will return. I'm then using a while loop to loop while the OleDBDataReader object has...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
15
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed...
21
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New...
1
by: adz1809 | last post by:
I'm having a problem with updating a record through a form. Here is the error: Server Error in '/AccoEndUser' Application....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.