Hi,
I'm doing the following code to connect to Access Db. The db1.mdb is placed in c:\db1.mdb. It giving me error "couldn't find file"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Data.OleDb;
namespace CustomerDB
{
class OleDbTest{
public static void Main()
{
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/db1.mdb");
//create the command object and store the sql query
OleDbCommand aCommand = new OleDbCommand("select * from customer_test", aConnection);
try
{
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
Console.WriteLine("This is the returned data from customer_test table");
//Iterate throuth the database
while(aReader.Read())
{
Console.WriteLine(aReader.GetInt32(0).ToString());
}
//close the reader
aReader.Close();
//close the connection Its important.
aConnection.Close();
Console.ReadLine();
}
//Some usual exception handling
catch(OleDbException e)
{
Console.WriteLine("Error: {0}", e.Errors[0].Message);
}
}
}
}