如何访问MS Access数据库 [英] how to access ms access database

查看:115
本文介绍了如何访问MS Access数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要从ms Access数据库中检索数据.


I required to retrieve data from ms access database

推荐答案

有很多示例.请不要忘记:
There are plenty of examples. Please do not forget: google is your friend[^]! :)


using System.Data.OleDb; //use this namespace
//create object of the oledb class
OleDbConnection con = new OleDbConnection();
//enter conncetion string via udl file expalnation given below

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\database.mdb;Persist Security Info=False" 
//Open the connection                        
con.Open();
//Her''s the query
string command ="select eid from Inquiry_Table";
OleDbCommand cmd = new OleDbCommand(command, con);
OleDbDataReader dr = cmd.ExecuteReader(); //executing the query

while(dr.Read()==true)
{
cboempid.Items.Add(dr[0].ToString());
}
con.Close();//closing the conncetion
con.Dispose();//removing connection object from memory




上面的代码将从访问数据库中读取值,并将数据添加到组合框中.

创建一个记事本文件并将其保存为扩展名.udl将文件打开到提供程序部分,选择Microsoft.Jet.OLEDB.4.0,然后浏览到您的访问文件的位置,单击测试连接,然后单击完成,以获取连接字符串执行上述步骤,然后使用记事本打开udl文件


对您的回答进行评分后,一旦发现有帮助
谢谢&问候;
基数.




The above code will read the value from an access database and will add data into the combobox

create a notepad file and save it with the extention .udl open the file into the provider section select Microsoft.Jet.OLEDB.4.0 and then browse for the location of ur access file click on test connection and ur done to go and inorder to get the connection string performn the above steps and then open the udl file with notepad


rate my answer once u find it helpful
Thanks & Regards;
Radix.


这篇关于如何访问MS Access数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆