Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. UI;
Using system. Data. oledb;
Namespace solog. acesstask
...{
/** // <Summary>
/// Auxiliary class of the data operation layer
/// Provides data sources and SQL operations
/// </Summary>
Public class getdata: system. Web. UI. Page
...{
Private oledbconnection _ myconn;
Private Static string dbpath = httpcontext. Current. server. mappath (configurationmanager. deleetpipeline ["dbpath"]);
Public getdata ()
...{
String connectstring = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + dbpath;
_ Myconn = new oledbconnection (connectstring );
}
Public oledbconnection myconn ()
...{
Try
...{
_ Myconn. open ();
}
Catch (system. Data. oledb. oledbexception E)
...{
Throw new exception (E. Message );
}
Return _ myconn;
}
Public void closeconn ()
...{
_ Myconn. Close ();
}
Public dataset getdataset (string SQL)
...{
// Obtain Dataset
Dataset DS = new dataset ();
Try
...{
Oledbdataadapter DAP = new oledbdataadapter (SQL, this. myconn ());
Dap. Fill (DS );
Return Ds;
}
Catch (system. Data. oledb. oledbexception E)
...{
Throw new exception (E. Message );
}
Finally
...{
Closeconn ();
}
}
/** // <Summary>
/// Obtain oledatareader
/// </Summary>
/// <Param name = "sqlstring"> SQL statement </param>
/// <Returns> oledatareader </returns>
Public oledbdatareader getreader (string sqlstring)
...{
// Obtain idatareader
Oledbdatareader datareader = NULL;
Oledbcommand dbcmd = new oledbcommand (sqlstring, this. myconn ());
Try
...{
Datareader = dbcmd. executereader (commandbehavior. closeconnection );
Return datareader;
}
Catch (system. Data. oledb. oledbexception E)
...{
Throw new exception (E. Message );
}
}
Public void excnonquery (string sqlstring)
...{
// Execute a commadnd with no return value
Oledbcommand exc = new oledbcommand (sqlstring, this. myconn ());
Exc. executenonquery ();
Exc. Connection. Close ();
}
Public int excscalar (string sqlstring)
...{
// The execution returns a single int value.
Oledbcommand exc = new oledbcommand (sqlstring, this. myconn ());
Int result = convert. toint32 (EXC. executescalar ());
Exc. Connection. Close ();
Return result;
}
}
}