Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I required to retrieve data from ms access database
Posted

There are plenty of examples. Please do not forget: google is your friend[^]! :)
 
Share this answer
 
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



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.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900