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
Solved

Using IsDBNull method of OleDBDataReader throws an error

Posted on 2008-10-25
4
1,063 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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