Asp.net[c#] Access database operations class

Source: Internet
Author: User
Asp.net[c#] Access database operations class

      
private string datapatch = configurationsettings.appsettings["Acessconn"]; Database Address private String datapatch = "Db/global.asa"; Database address//////get DataSet//////query statement///public DataSet GetDataSet (string commandtext) {string strconnection = "Prov ider=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; //////Get Table//////query Statement///public DataTable getdatatable (string commandtext) {string strconnection = "PROVIDER=MICR Osoft. 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; //////Gets the value of a column in a row///the name of the///column///the primary key value///the table's primary keys///column///public string getdatacolum (string strcolumnname, Strin G 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 (); OleDbDataAdapter myadpater = new OleDbDataAdapter (strcommandtext,myconnection); OleDbCommandBuilder Mybuilder = new OleDbCommandBuilder (myadpater); DataSet myDataSet = new DataSet (); Myadpater.missIngschemaaction = MissingSchemaAction.AddWithKey; Myadpater.fill (myDataSet); Myconnection.close (); DataTable mytable = mydataset.tables[0]; DataRow mydr = mytable. Rows.find (Strcolumnvalue); String MYDC = Mydr[strcolumnname]. ToString (); return MYDC; //////update A field//////to update the name of the field///the value to be updated///the value of the key///table in the table the values of key in the list are public void///(string updatecolum, String strvalue, String strtablename, String Strcolumnkey, String strcolumnvalue) {string strconnection = ' PROVIDER=MICR Osoft. jet.oledb.4.0; "+" "Data source=" + Server.MapPath (Datapatch); String strcommandtext = "Select" + Strcolumnkey + "," + Strcolumnname + "from" + strtablename; OleDbConnection myconnection = new OleDbConnection (strconnection); Myconnection.open (); OleDbDataAdapter myadpater = new OleDbDataAdapter (strcommandtext,myconnection); OleDbCommandBuilder Mybuilder = new OleDbCommandBuilder (myadpater); DataSet myDataSet = new DataSet (); Myadpater.missingschemaaction = MissingSchemaAction.AddWithKey; Myadpater.fill (Mydataset,strtablename); DataRow Drfindrow = Mydataset.tables[strtablename]. Rows.find (Strcolumnvalue); Drfindrow[strcolumnname] = strvalue; Myadpater.update (Mydataset,strtablename); Myconnection.close (); //////Add Row//////the collection of fields in this row///the corresponding value of the field collection in this row///the table name///the primary key public void AddRow (string []columns, String []columnva Lue, String strtablename, String strcolumnkey) {string strconnection = "provider=microsoft.jet.oledb.4.0;" + "Data Sou Rce= "+ Server.MapPath (Datapatch); String strcolumncount = ""; foreach (string thiscolunmname in columns) {Strcolumncount = Thiscolunmname + "," + Strcolumncount;} String strcommandtext = "Select" + strcolumncount + Strcolumnkey + "from" + strtablename; 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,strtablename); DataRow NewRow = Mydataset.tables[strtablename]. NewRow (); for (int i = 0; i < columns. Length;i + +) {string strcolumnname = Columns[i]. ToString (); Newrow[strcolumnname] = Columnvalue[i]. ToString (); } Mydataset.tables[strtablename]. Rows.Add (NewRow); Myadpater.update (Mydataset,strtablename); Myconnection.close (); //////Update Data row//////the column collection to update///the corresponding value of the column collection to update///the owning table name///the table primary key///row belongs to the id public void Updaterow (string []columns, Stri ng []columnvalue, String strTableName, String Strcolumnkey, String strcolumnvalue) {string strconnection = "Provider=mic Rosoft. jet.oledb.4.0; "+" "Data source="

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.