?e1ú×?′óμ?web?a·¢×ê?′í????°??ê?é???£? add data to the database using ado
tools used : visual c# .net
this program shows how to insert data in an access database using ado and sql query. i have an access 2000 database in project/bin/debug directory. my database name is mctest.mdb. you can create your own database and copy in your project's debug directory. i am not attaching database with this code because of size problem.
i have a table 'developer' in this database which has four columns. i am inserting values into two columns name and address in this code.
using system; using system.data; using system.data.oledb; namespace adonetwritequery { /// <summary> /// summary description for class1. /// </summary> class class1 { static void main(string[] args) { string strdsn = "provider=microsoft.jet.oledb.4.0;data source=c://mctest.mdb"; string strsql = "insert into developer(name, address ) values( 'newname', 'newaddress')" ;
// create objects of adoconnection and adocommand oledbconnection myconn = new oledbconnection(strdsn); oledbcommand mycmd = new oledbcommand( strsql, myconn ); try { myconn.open(); mycmd.executenonquery(); } catch (exception e) { console.writeline("oooops. i did it again:/n{0}", e.message); } finally { myconn.close(); }