旅游景点 旅游攻略 生活知识 生活百科 文化旅游 旅游景区 昆明旅游 桂林旅游 乡村旅游 上海旅游 知识问答

C#怎么往mdb编辑写入数据

时间:2026-04-23 07:25:45

1、创建并打开一个OleDbConnection对象

string strConn = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = sample.mdb " ;OleDbConnection myConn = new OleDbConnection ( strCon ) ;myConn.Open ( ) ;

2、创建插入的SQL语句

string strInsert = " INSERT INTO books ( bookid , booktitle , bookauthor , bookprice , bookstock ) VALUES ( " ;strInsert += t_bookid.Text + ", '" ;strInsert += t_booktitle.Text + "', '" ;strInsert += t_bookauthor.Text + "', " ;strInsert += t_bookprice.Text + ", " ;strInsert += t_bookstock.Text + ")" ;

3、创建一个OleDbCommand对象

OleDbCommand inst = new OleDbCommand ( strInsert , myConn ) ;

4、使用OleDbCommand对象来插入数据

inst.ExecuteNonQuery ( ) ;

5、关闭OleDbConnection

myConn.Close ( ) ;

© 2026 途途旅游
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com