using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSharpAccess
{
class Program
{
static void Main(string[] args)
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/school.mdb");
conn.Open();
string sql = "select * from student";
OleDbCommand command = new OleDbCommand(sql, conn);
OleDbDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount;i++ )
{
Console.Write("{0} ", reader[i]);
}
Console.WriteLine();
}
}
finally
{
reader.Close();
conn.Close();
}
}
}
}
C#访问ACCESS文件的简单实例
C#读取Access数据库
最新推荐文章于 2021-03-25 17:41:47 发布
本文展示了一个使用C#从Access数据库中读取数据的例子。通过连接字符串指定数据库位置,并利用OleDbConnection、OleDbCommand及OleDbDataReader完成数据读取操作。
3万+

被折叠的 条评论
为什么被折叠?



