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数据库的链接和操作典型代码
最新推荐文章于 2025-09-06 22:56:13 发布
