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??
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted Jan 20, 2007, 10:32 PM
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());
}...