Solved

Using IsDBNull method of OleDBDataReader throws an error

Posted on 2008-10-25
4
1,061 Views
Last Modified: 2013-12-17
I am using an OleDbDataReader to retrieve information from an Excel Spreadsheet. When I attempt to test a column for a null value using the IsDBNull method, I get an error "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
The connection for viewing your linked Microsoft Excel worksheet was lost.".
I cannot see what I am doing wrong, having compared my code to lost of examples. Can anyone advise or help me troubleshoot further
OleDbDataReader dr;

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Uploads\Shelters.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

OleDbConnection conn = new OleDbConnection(connectionString);

conn.Open();

OleDbCommand cmd = new OleDbCommand("Select route from [AA$]", conn);

dr = cmd.ExecuteReader();

string route;

while (dr.Read())

{

       if (dr.IsDBNull(0)) //This line produces the error

       {

          route = "";

       }

       else

       {

          route = dr.GetString(0);

       }

}

dr.Close();

conn.Close();

Open in new window

0
Comment
Question by:Phil Catterall
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22802773
I guess your dr is null .. first check that ...
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22803066
i tried your code and did not find any exceptions
in one case i had a empty cell and in other case it had value
in case of empty cell dbnull returned true and it did not throw any error and in case of value i got the value back
0
 

Author Closing Comment

by:Phil Catterall
ID: 31509948
Well how weird. Having read it worked for you, I did a bit more research on the net, and found another extended property called IMEX, which I added as IMEX=1, re-tried and it worked. Then I removed it and it still works. I haven't changed anything !! Code still open, haven't reloaded, no reboot or anything.
Anyway, thanks for your input.
0
 

Author Comment

by:Phil Catterall
ID: 22803240
Well how weird. Having read it worked for an expert, I did a bit more research on the net, and found another extended property called IMEX, which I added as IMEX=1, re-tried and it worked. Then I removed the IMEX=1 and it still works! I haven't changed anything !! IDE/Code still open, haven't reloaded, no reboot or anything.
Anyway, thanks all for the input.- I will put this one down to an undocumented Microsoft feature (strange, haven't seen any of those before :-) )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now