directxBOB
asked on
Connecting to NorthWind Access Database?
I am trying to connect to an Access Database to do some testing, I have the following:
public System.Data.DataSet GetAuthorData(string lcID)
{
if (lcID == "")
lcID = "%";
DataSet ds = new DataSet();
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0;Data Source=c:\\Northwind 2007.accdb");
OleDbDataAdapter oAdapter = new OleDbDataAdapter();
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("select * from Customer List where ID like '" + lcID + "%'", aConnection);
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("This is the returned data from emp_test table");
oAdapter.SelectCommand = aCommand;
oAdapter.Fill(ds, "Authors");
//close the reader
aReader.Close();
//close the connection Its important.
aConnection.Close();
}
//Some usual exception handling
catch(OleDbException e)
{
return null;
}
return ds;
}
@ aConnection.Open();
An exception is thrown and the result is null. So I believe the connection is the issue:
OleDbConnection aConnection = new OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0;Data Source=c:\\Northwind 2007.accdb");
Any ideas on what may be wrong with the connection?
public System.Data.DataSet GetAuthorData(string lcID)
{
if (lcID == "")
lcID = "%";
DataSet ds = new DataSet();
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=
OleDbDataAdapter oAdapter = new OleDbDataAdapter();
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("select * from Customer List where ID like '" + lcID + "%'", aConnection);
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("This is the returned data from emp_test table");
oAdapter.SelectCommand = aCommand;
oAdapter.Fill(ds, "Authors");
//close the reader
aReader.Close();
//close the connection Its important.
aConnection.Close();
}
//Some usual exception handling
catch(OleDbException e)
{
return null;
}
return ds;
}
@ aConnection.Open();
An exception is thrown and the result is null. So I believe the connection is the issue:
OleDbConnection aConnection = new OleDbConnection("Provider=
Any ideas on what may be wrong with the connection?
what sort of exception
OleDbConnection aConnection = new OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0;Data Source=c:\\Northwind2007.a ccdb");
There should be no space.
There should be no space.
ASKER
base {System.Data.Common.DbExce ption} = {"Could not find installable ISAM."}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.