ASP.NET的ACCESS数据库操作类

2013 年 12 月 23 日4160

ASP.NET的ACCESS数据库操作类

http://http://www.zjjv.com//.cn/eschool/2006年06月30日09:20来源:作者:JavaProgramers

【文章摘要】网上很多都是操作SQL SER 的,整理了一下,不是很完善,但不影响使用,呵呵……

//网上很多都是操作SQL SER 的,整理了一下,不是很完善,但不影响使用,呵呵……

//private string datapatch = ConfigurationSettings.AppSettings["acessconn"];//数据库地址

private string datapatch = "db/global.asa";//数据库地址

/// /// 取得dataset

// /// 查询语句

/// public DataSet GetDataSet(string Commandtext)

{ string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath(datapatch);

string strCommandText = Commandtext;

OleDbConnection myConnection = new OleDbConnection(strConnection);

myConnection.Open();

OleDbDataAdapter myAdpater = new OleDbDataAdapter(strCommandText,myConnection);

OleDbCommandBuilder myBuilder = new OleDbCommandBuilder(myAdpater);

DataSet myDataset = new DataSet();

myAdpater.Fill(myDataset);

myConnection.Close();

return myDataset;

}

/// /// 取得表

/// /// 查询语句

/// public DataTable GetDataTable(string Commandtext)

{ string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath(datapatch);

string strCommandText =Commandtext;

OleDbConnection myConnection = new OleDbConnection(strConnection);

myConnection.Open();

OleDbDataAdapter myAdpater = new OleDbDataAdapter(strCommandText,myConnection);

OleDbCommandBuilder myBuilder = new OleDbCommandBuilder(myAdpater);

DataSet myDataset = new DataSet();

myAdpater.Fill(myDataset);

DataTable mytable = myDataset.Tables[0];

myConnection.Close();

return mytable;

}

/// /// 取得某行的某列的值

/// /// 列的名称

/// 所属表名

/// 表的主键

/// 列所属的主键值

/// public string GetDataColum(string strColumnName,string strTableName,string strColumnkey,string strColumnValue)

{ string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath(datapatch);

string strCommandText = "select "+strColumnName+","+strColumnkey+" from "+strTableName;

OleDbConnection myConnection = new OleDbConnection(strConnection);

myConnection.Open();

点击阅读更多学院相关文章>>

责任编辑:徐洋

0 0