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

2025-04-29 00:31:42

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 I鲍伊酷雪NTO books ( bookid , booktitle , bo泠贾高框okauthor , 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、关闭OleDbConnectionmyConn.Close ( ) ;

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢