Need Help on Connecting WindowForm to MS Access Tables
I know to use ADO.NET to connect Window Form to SQL Server Database, but I don't know how to connect to MS Access Database Table! Could someone please help??
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Scott LysleRank #49 · 31K reputationPosted Jan 20, 2007, 5:32 PM EST
Normally you'd put the connection strings into the settings, but here is a simple example of running dynamic SQL against a local access database through an OleDb connection:
string
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\SomeLDB\\SomeLocal.mdb";OleDbConnection conn = new OleDbConnection(strConn); try
{
conn.Open();
string sSql = "SELECT DISTINCT aField FROM aTable";
OleDbCommand cmd = new OleDbCommand(sSql, conn);
OleDbDataReader dr = cmd.ExecuteReader(); if (dr.HasRows == true)
{
while (dr.Read())
{
try
{
cboFieldVals.Items.Add(dr.GetValue(0).ToString());
}...