// generic method to fetch data from OleDb source into a reader
OleDbDataReader fetchReader ( string query, string db ) {
// connect to data source
OleDbConnection myConn = new OleDbConnection (
"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" +
Server.MapPath ( "~/app_data/" + db + ".mdb" ) );
// initialize command object with query
OleDbCommand myCmd = new OleDbCommand ( query, myConn );
// open connection
myConn.Open ( );
// return datareader
return myCmd.ExecuteReader ( CommandBehavior.CloseConnection );
}
// generic method to fetch data from OleDb source into a dataset
DataSet fetchData ( string query, string db ) {
// connect to data source
OleDbConnection myConn = new OleDbConnection (
"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" +
Server.MapPath ( "~/app_data/" + db + ".mdb" ) );
// initialize dataadapter with query
OleDbDataAdapter myAdapter = new OleDbDataAdapter ( query, myConn );
// initalize and fill dataset with query results
DataSet myData = new DataSet ( );
myAdapter.Fill ( myData );
// return dataset
return myData;
}
// generic method to fetch scalar value from SQL Server
object fetchScalar ( string query, string db ) {
// connect to data source
OleDbConnection myConn = new OleDbConnection (
"Provider=Microsoft.Jet.OleDb.4.0; Data Source=" +
Server.MapPath ( "~/app_data/" + db + ".mdb" ) );
// initialize command object with query
OleDbCommand myCmd = new OleDbCommand ( query, myConn );
// open connection
myConn.Open ( );
// get scalar
object scalar = myCmd.ExecuteScalar ( );
// close connection
myConn.Close ( );
// return scalar
return scalar;
}