Solved

Using IsDBNull method of OleDBDataReader throws an error

Posted on 2008-10-25
4
1,074 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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