使用C 向ACCESS中插入資料

2022-05-16 13:19:54 字數 1473 閱讀 3390

使用c#向access中插入資料

1.建立並開啟乙個oledbconnection物件

string strconn = " provider = microsoft.jet.oledb.4.0 ; data source = sample.mdb " ; oledbconnection myconn = new oledbconnection ( strconn ) ; 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 ( ) ;

1.建立並開啟乙個oledbconnection物件

string strconn = " provider = microsoft.jet.oledb.4.0 ; data source = sample.mdb " ; oledbconnection myconn = new oledbconnection ( strconn ) ; 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 ( ) ;

c 向Access插入資料成功,資料庫中卻沒有資料

在用vs的視窗應用程式操作access時,系統會把這個資料庫檔案複製到輸出目錄bin debug中,那麼在進行資料操作的時候實際上是在對bin debug中的資料庫檔案進行的,而原庫檔案是不受影響。也即是說,每次執行除錯程式時,vs都會從我們指定的目錄拷貝乙份到debug下面,我們所 操作的acce...

從Sql向Access中大批量插入資料

注意 如果想使用這個方法,要保證存放sql資料庫的主機能夠訪問到access資料庫的存放位置,如果不在同乙個電腦上,並且access資料庫檔案不能設定區域網共享,那麼這個方法無效!insert into openrowset microsoft.jet.oledb.4.0 d school.mdb ...

sql向表中插入資料

例項 insert into 捲菸庫存表 捲菸品牌,庫存數量,庫存單價,庫存金額 select 紅塔山新勢力 100,12,1200 union all select 紅塔山人為峰 100,22,null union all select 雲南映像 100,60,500 union all sele...