C#access Database Operations

Source: Internet
Author: User
Tags auth access database

More messy, there is time to organize it.

1Provider=microsoft.jet.oledb.4.0; Persist Security Info=false;data Source=c:/d.mdb; Jet Oledb:database password=123456!"2 3 4  Private voidGetcon ()5        {6        stringstrconnection="provider=microsoft.jet.oledb.4.0;";7strconnection+=@"Data Source=c:\begaspnet\northwind.mdb";8 9OleDbConnection objconnection=NewOleDbConnection (strconnection);Ten  One  A Objconnection.open (); - objconnection.close (); -  the}


Open in an exclusive way

FILE--Information--encryption/decryption

Provider=microsoft.jet.oledb.4.0; Jet Oledb:database password=123456789;D ATA source=D:\ToWife.mdb;1.SetDbconnection=server.createobject ("ADODB. CONNECTION") DBPath= Server.MapPath ("Customer.mdb") dbconnection. Open"driver={microsoft Access Driver (*.mdb)};d bq="&Dbpathsql="select * from auth where id=""& user_id &"""SET uplist=DbConnection. EXECUTE (SQL)2.SetDbconnection=server.createobject ("ADODB. Connection") DBPath= Server.MapPath ("Customer.mdb") dbconnection. Open"Provider=Microsoft.Jet.OLEDB.4.0;Data source="&Dbpathsql="select * from auth where id=""& user_id &"""SET uplist=DbConnection. EXECUTE (SQL)3. DBPath= Server.MapPath ("Customer.mdb")SetSession"RS") =server.createobject ("ADODB. Recordset")"Rs=server.createobject ("ADODB. Recordset")Connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data source="&Dbpathsql="select * from auth where id=""& user_id &"""session ("RS"). Open Sql,connstr,1,3

Connection access2007

1 New OleDbConnection (@ "provider=microsoft.ace.oledb.12.0; User id=admin;data source=d:/database. accdb; Jet oledb:database password=123456;

Connection access2003

New OleDbConnection (@ "provider=microsoft.jet.oledb.4.0; User id=admin";D ata source=d:/database. mdb; Jet oledb:database password=123456; " )

Build an ODBC source

set conn=server.createobject ("adodb.connection""dsn= xxx uid=; Pwd=123456;database=xxx"

Crack password

1   Public Static stringGetmdbpassword (stringfile)2         {                      3             //unencrypted MDB file, a value of one byte per interval between 0x42 and 0x614             byte[] Basebyte = {0xBE,0xec,0x65,0x9c,0xFE,0x28,0x2b,0x8a,0x6c,0x7b,0xCD,0XDF,0x4f,0x13,0xf7,0xb1, };5             byteFlagbyte =0x0c;//the value at the Mark 0x626             stringPassword ="";7             Try8             {9FileStream fs =File.openread (File);TenFs. Seek (0x14, seekorigin.begin); One                 bytever = (byte) fs. ReadByte ();//get Access version, 1 is access2000/2003, 0 is Access97 AFs. Seek (0x42, seekorigin.begin); -                 byte[] bs =New byte[ -]; -                 if(FS. Read (BS,0, -) != -)return ""; the                 byteFlag = (byte) (bs[ +] ^flagbyte); -                  for(inti =0; I < -; i++) -                 { -                     byteB = (byte) (Basebyte[i] ^ bs[i *2]); +                     ifI2==0&& ver = =1) b ^= Flag;//Access 2000/2003 -                     if(B >0) Password + = (Char) b; +                 } A             } at             Catch { } -  -             return(Password. Equals ("") ?"No password!": password); -}

Up

1 Private intUpstringsql)2         {3             intindex =0;4OleDbConnection con =Getcon (); 5             Try6             {7                 if(con!=NULL)8                 {9 con. Open ();TenOleDbCommand OC =NewOleDbCommand (sql, con); One                     returnOC. ExecuteNonQuery (); A                 } -                 return 0; -             } the             Catch(Exception) -             { -                 return 0; -             } +}

Select

1  PrivateDataTableSelect(stringsql)2         {3DataTable dt =NewDataTable ();4OleDbConnection con =Getcon ();5             Try6             {7                 if(con!=NULL)8                 {9 con. Open ();Ten                     //get a data set with OleDbDataAdapter OneOleDbDataAdapter mycommand =NewOleDbDataAdapter (Sql,con); ADataSet myDataSet =NewDataSet (); -                     //bind a dataset to a Books data table - Mycommand.fill (myDataSet); the con. Close (); -                     returnmydataset.tables[0];  -                 } - con. Close (); +                 return NULL; -             } +             Catch(Exception) A             { at con. Close (); -                 return NULL; -             } -}

operation function Addprimarykey () for primary key'add primary key to [number] fieldDim strSQL as Stringstrsql="ALTER table 1 ADD CONSTRAINT Primary_key" _&"PRIMARY KEY (number)"CurrentProject.Connection.Execute strsqlend functionfunction dropprimarykey ()'Delete primary KeyDim strSQL as Stringstrsql="ALTER table 1 Drop CONSTRAINT Primary_key"CurrentProject.Connection.Execute strsqlend Function

C#access Database Operations

Related Article

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.