473,569 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invalid cast prob with oleDBdataReader

....
Dim rdr As OleDbDataReader = cmd.ExecuteRead er
If rdr.GetString(1 ).ToString.Leng th > 0 Then
Console.WriteLi ne(rdr.GetStrin g(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.Ge tString(1).ToSt ring)...

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

Thanks
Nov 21 '05 #1
2 2975
If Not rdr.IsDBNull(1) Then
Console.WriteLi ne(rdr.GetStrin g(1).ToString)
End If

hope that helps..
Imran.

"James" <an*******@disc ussions.microso ft.com> wrote in message
news:11******** *************** *****@phx.gbl.. .
...
Dim rdr As OleDbDataReader = cmd.ExecuteRead er
If rdr.GetString(1 ).ToString.Leng th > 0 Then
Console.WriteLi ne(rdr.GetStrin g(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.Ge tString(1).ToSt ring)...

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.WriteLi ne(rdr.GetStrin g(1).ToString)
End If

hope that helps..
Imran.

"James" <an*******@disc ussions.microso ft.com> wrote in messagenews:11******* *************** ******@phx.gbl. ..
...
Dim rdr As OleDbDataReader = cmd.ExecuteRead er
If rdr.GetString(1 ).ToString.Leng th > 0 Then
Console.WriteLi ne(rdr.GetStrin g(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.Ge tString (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
5588
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 can't seem to use this as the first pram OleDbDataReader reader = new OleDbDataReader() i.e public static string Read(OleDbDataReader reader,...
0
1677
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. 3. Same problem on two different computers running Win 2003.
0
1371
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 records. I would like to know does the OleDbDataReader contain the actual information on each record i.e. the fields in the database and their...
5
3405
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 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to...
3
2270
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 DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
1
4861
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 specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal...
15
2227
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 spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has...
21
1901
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 DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;" & _
1
2861
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. -------------------------------------------------------------------------------- Must declare the variable '@Title'. Description: An unhandled exception occurred during the execution of the current web request....
0
7697
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.