OleDbException was unhandled by user code - Unspecified error
The following error keeps popping up randomly when my program is running.
Quite new to this so i'm not sure how to go about catching this... Did a
quick search alrd but nothing seems to help.
The following is part of my code:
protected DBBase(string tableName, string primary_key)
{
string s = Application.StartupPath + "\\alliancedb.accdb";
conn = new
OleDbConnection(String.Format("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source={0}", s));
if (conn.State == ConnectionState.Closed)
{
conn.Open();
dataset = new DataSet();
//query statement
string sqlStatement = String.Format("Select * from {0}
order by {1} ASC", tableName, primary_key);
//run sql
DBadpt = new OleDbDataAdapter(sqlStatement, conn);
oOrderDetailsCmdBuilder = new OleDbCommandBuilder(DBadpt);
DBadpt.Fill(dataset);
dbTab = dataset.Tables[0];
dbTab.TableName = this.tableName = tableName;
rows = dbTab.Rows;
}
else if (conn.State == ConnectionState.Open)
{
conn.Close();
conn.Open();
dataset = new DataSet();
//query statement
string sqlStatement = String.Format("Select * from {0}
order by {1} ASC", tableName, primary_key);
//run sql
DBadpt = new OleDbDataAdapter(sqlStatement, conn);
oOrderDetailsCmdBuilder = new OleDbCommandBuilder(DBadpt);
DBadpt.Fill(dataset);
dbTab = dataset.Tables[0];
dbTab.TableName = this.tableName = tableName;
rows = dbTab.Rows;
}
}
No comments:
Post a Comment