• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

OleDb.... Exception handling

Hello,

is there a particular exception class that handles errors thrown by System.Data.OleDb?

thanks



0
brdrok
Asked:
brdrok
  • 2
  • 2
1 Solution
 
Razzie_Commented:
Well yes there is the System.Data.OleDb.OleDbException class.
0
 
brdrokAuthor Commented:
hey Razzie,

thanks for the answer...got another question for you (increased point value to 100).  why does the code go to the "Exception" as opposed to the "System.Data.OleDb.OleDbException" catch block?

try
{
      string sqlString = "SELECT * FROM " + myRegion + " WHERE Status_FK = " + myStatus;
      System.Data.OleDb.OleDbConnection myConn = new OleDbConnection(CONNSTRING);
      System.Data.OleDb.OleDbDataAdapter myDA = new OleDbDataAdapter();  <---i create a mistake here
      System.Data.DataSet myDS = new DataSet();
      myDA.Fill(myDS, "ProgressReport");   <----Exception is thrown here and goes to the "Exception" catch block.
}
catch (System.Data.OleDb.OleDbException oleEx)
{
                MessageBox.Show(oleEx.Message);
      return;
}
catch (Exception ex)
{
      MessageBox.Show(ex.Message);
      return;
}
finally
{
      //TODO: DO CLEAN UP HERE
}
0
 
Razzie_Commented:
OleDbExceptions are only thrown when something goes wrong at the server, for example invalid table name, non-existend column names, etc.

The error you create (not setting the select query) is an InvalidOperationException. It doesn't have anything to do with the actual database data, or table structures.

I think that when you enter something invalid in your sql query, like an invalid table name, the OleDbException will be thrown.

HTH,

Razzie
0
 
brdrokAuthor Commented:
Thanks Razzie for the very useful info.....

you rock....
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now