Copy Code code as follows:
Using System;
Using System.Configuration;
Using System.Data;
Using System.Data.OleDb;
Using System.Xml;
Using System.Collections;
Namespace Website.command
{
<summary>
Summary description of the wsplus.
</summary>
public class AccessClass:System.Web.UI.Page
{
private static OleDbConnection sconn = null;
public static string _returnvalue = "0";
Public Wsplus ()
{
//
TODO: Add constructor logic here
//
sconn = new OleDbConnection ("provider=" Microsoft.jet.oledb.4.0;data "source=" + Server.MapPath ("/. Db.mdb ") +"; ");
}
<summary>
Open Data
</summary>
private static void Connopen ()
{
if (sconn. State= "=connectionstate.closed"
Try
{
Sconn. Open ();
}
catch (Exception ex)
{
throw new Exception ("Database initialization error!!!" +ex. message);
}
}
<summary>
Close Database
</summary>
public void Connclose ()
{
if (sconn. state = "=" ConnectionState.Open)
Try
{
Sconn. Close ();
}
catch (Exception ex)
{
throw new Exception ("OLE DB close error!" +ex. message);
}
}
<summary>
Stored procedure type cmd initialization!
</summary>
<param name= "HT" ></param>
<param name= "Scmd" ></param>
<param name= "Proc" ></param>
private static void Configcmd (Hashtable ht,oledbcommand scmd,string sqls)
{
if (scmd = "=" null) throw new ArgumentException ("Scmd uninitialized");
if (HT!= NULL && ht. Count!= 0)
{
IDictionaryEnumerator items = ht. GetEnumerator ();
while (items. MoveNext ())
SCMD.PARAMETERS.ADD (Makeparam) (items. Key.tostring (), items. Value.tostring ()));
}
Scmd.connection = sconn;
Scmd.commandtext = Sqls;
}
private static void Configcmd (ArrayList alist,oledbcommand scmd,string sqls)
{
if (scmd = "=" null) throw new ArgumentException ("Scmd uninitialized");
if (alist!= null && alist. Count!= 0)
{
foreach (object items in alist)
{
Command.Model.typeFiles CMT = (Command.Model.typeFiles) items;
SCMD.PARAMETERS.ADD (Makeparam) (CMT. Fkey.tostring (), CMT. Fvalue1.tostring (), CMT. Fvalue2.tostring ()));
}
}
Scmd.connection = sconn;
Scmd.commandtext = Sqls;
}
private static OleDbParameter Makeparam (string key,string value)
{
return new OleDbParameter (Key,value);
}
private static OleDbParameter Makeparam (string key,string f1,string F2)
{
OleDbParameter par = null;
if (F2. ToUpper () = "=" "STRING"
{
par = new OleDbParameter (Key,oledbtype.varchar);
}
else if (F2. ToUpper () = "=" "INTEGER"
{
par = new OleDbParameter (Key,oledbtype.integer);
}
else if (F2. ToUpper () = "=" "lstring")
{
par = new OleDbParameter (Key,oledbtype.longvarchar);
}
Try
// {
Par. Value = F1;
// }
catch (Exception e)
// {
throw new Exception (E.message + "" + key + "" + F1 + "" + F2);
// }
Return par;
}
public void Execconfig (Hashtable ht,string sqls)
{
OleDbCommand cmd= "New OleDbCommand" ();
Connopen ();
Configcmd (HT,CMD,SQLS);
ExecuteNonQuery (CMD);
}
public void Execconfig (ArrayList alist,string sqls)
{
OleDbCommand cmd= "New OleDbCommand" ();
Connopen ();
Configcmd (ALIST,CMD,SQLS);
ExecuteNonQuery (CMD);
}
<summary>
Data manipulation
</summary>
<param name= "cmd" ></param>
private static void ExecuteNonQuery (OleDbCommand cmd)
{
Command.accessclass cw = new Accessclass ();
Try
{
_returnvalue = cmd. ExecuteNonQuery (). ToString ();
}
catch (Exception e) {throw new Exception ("Run Exec error!" +e.message);}
Finally
{
Cmd. Parameters.clear ();
Cw.connclose ();
}
}
<summary>
SQL statement Type DataTable
</summary>
<param name= "Sqls" ></param>
<returns></returns>
Public DataTable returndatatablebysql (Hashtable ht,string sqls)
{
DataTable dt= "New DataTable" ();
OleDbCommand cmd= "New OleDbCommand" ();
Configcmd (HT,CMD,SQLS);
OleDbDataAdapter sda= "New OleDbDataAdapter (CMD);
Sda. Fill (DT);
Cmd. Parameters.clear ();
return DT;
}
Public OleDbDataReader getreader (Hashtable ht,string sqls)
{
Connopen ();
OleDbCommand cmd= "New OleDbCommand" ();
Configcmd (HT,CMD,SQLS);
OleDbDataReader reader = cmd. ExecuteReader ();
return reader;
Reader. Close ();
Cmd. Parameters.clear ();
Connclose ();
}
Public OleDbDataReader getreader (ArrayList alist,string sqls)
{
Connopen ();
OleDbCommand cmd= "New OleDbCommand" ();
Configcmd (ALIST,CMD,SQLS);
OleDbDataReader reader = cmd. ExecuteReader ();
return reader;
Reader. Close ();
Cmd. Parameters.clear ();
Connclose ();
}
public string returnvalue
{
Get
{
return _returnvalue;
}
Set
{
_returnvalue = value;
}
}
}
}