using system;
using system.data.oledb;
class oledbtest{
public static void main()
{
/創建數據庫連接
oledbconnection aconnection = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=c:\\db1.mdb");
/創建command對象並保存sql查詢語句
oledbcommand acommand = new oledbcommand("select * from emp_test", aconnection);
try
{
aconnection.open();
/創建datareader 對象來連接到表單
oledbdatareader areader = acommand.executereader();
console.writeline("this is the returned data from emp_test table");
/關閉reader對象
areader.close();
/關閉連接,這很重要
aconnection.close();
}
/一些通常的異常處理
catch(oledbexception e)
{
console.writeline("error: {0}", e.errors[0].message);
}
}
}
C#與ACCESS數據庫的鏈接和操作典型代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.