Visual Studio 2017(C#)连接Microsoft Access 2010

本文介绍了如何在Visual Studio 2017中通过C#代码连接并查询Microsoft Access 2010创建的数据库test.accdb。步骤包括创建数据库、新建web窗体、编写代码引用OleDb命名空间,并展示如何读取数据到文本控件。关键在于使用正确的提供者(Provider=Microsoft.ACE.OLEDB.12.0)以识别accdb格式的数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先用Microsoft Access 2010创建一个数据库test.accdb。


2.打开Visual Studio 2017创建一个web窗体。


3.双击“登录”按钮进去编写代码,记得先引用命名空间using System.Data.OleDb;

        string str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:/御用闲人办公网站系统/御用闲人/test.accdb;";
        OleDbConnection OleDbConnection = new OleDbConnection(str);
        OleDbConnection.Open();
        OleDbCommand sqlcmd = new OleDbCommand(@"select * from test where ID='lihu'", OleDbConnection);  
        OleDbDataReader reader = sqlcmd.ExecuteReader();
        if(reader.Read())
        {
            username.Text = reader["ID"].ToString();
            password.Text = reader["pa

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值