How do I connect to an Access 2003 or 2007 database from Visual Studio 2008. I found the following code on a website and have tried it but get 1 error to do with the connection string:
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con;
OleDbCommand cmd;
OleDbDataAdapter myDA;
DataSet myDataSet;
con = OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Swantrax.mdb; Persist Security Info=False;");
con.Open();
cmd = OleDbCommand("SELECT * From Parts", con);
myDA = OleDbDataAdapter(cmd);
myDataSet = DataSet();
myDA.Fill(myDataSet, "MyTable");
DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView;
con.Close();
con = Nothing;
}
When I buid the code I get an error with the connection string:
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Swantrax.mdb; Persist Security Info=False;");
It does not like the Source string.
Any ideas?
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con;
OleDbCommand cmd;
OleDbDataAdapter myDA;
DataSet myDataSet;
con = OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Swantrax.mdb; Persist Security Info=False;");
con.Open();
cmd = OleDbCommand("SELECT * From Parts", con);
myDA = OleDbDataAdapter(cmd);
myDataSet = DataSet();
myDA.Fill(myDataSet, "MyTable");
DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView;
con.Close();
con = Nothing;
}
When I buid the code I get an error with the connection string:
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Swantrax.mdb; Persist Security Info=False;");
It does not like the Source string.
Any ideas?