C#与ACCESS数据库的链接和操作典型代码
2012-05-22 14:21
281 查看
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);
}
}
}
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数据库
- C#操作IIS的代码,方便以后查阅
- C# WORD操作实现代码
- C#操作Access数据库的例子
- C# 链接Sql和Access数据库语句
- 静态页面下用javascript操作ACCESS数据库(读增改删)的代码
- C#中,当鼠标移动到控件上,动态显示提示内容 -> 用代码操作ToolTip
- C# 操作数据库就的那点代码
- C# WORD操作实现代码
- C#字符操作一些代码
- C#操作ACCESS数据库
- C#各种文件操作的代码与注释
- 收集的C#和Word操作的一些代码(本人未经测试)
- c#/ASP.NET操作cookie(读写)代码示例
- C#操作IIS代码
- C# 连接ACCESS数据库代码实例
- 爬虫技术(六)-- 使用HtmlAgilityPack获取页面链接(附c#代码及插件下载)
- c# 线程和Invoke互操作万用代码
- c#对Access数据库的操作
- 操作 SQL Server Mobile 2005 数据库的常用 C# 代码