G
gamall
hi
i use visual studio 2005 c# to access database (access 2007 enterprise
edition). i copied the following code from a book. However i get an
error in runtime. that the program can not locat the "filename.mdb" .
however my database file name is " filename.accdb"
how do i fix this problem? i am running this program on vista home
edition.
thanks
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string oledbConnectionString = "Provider =
Microsoft.ACE.OLEDB.12.0;Data Source=" +
@"C:\Users\gamalt\Documents\" + "Database2.accdb;";
string queryString = (" select id from Database2.table1");
using (OleDbConnection connection = new OleDbConnection
(oledbConnectionString))
{
OleDbCommand command = new OleDbCommand(queryString,
connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader(); // i
get the error here
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
}
}
i use visual studio 2005 c# to access database (access 2007 enterprise
edition). i copied the following code from a book. However i get an
error in runtime. that the program can not locat the "filename.mdb" .
however my database file name is " filename.accdb"
how do i fix this problem? i am running this program on vista home
edition.
thanks
using System;
using System.Data;
using System.Data.OleDb;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string oledbConnectionString = "Provider =
Microsoft.ACE.OLEDB.12.0;Data Source=" +
@"C:\Users\gamalt\Documents\" + "Database2.accdb;";
string queryString = (" select id from Database2.table1");
using (OleDbConnection connection = new OleDbConnection
(oledbConnectionString))
{
OleDbCommand command = new OleDbCommand(queryString,
connection);
connection.Open();
OleDbDataReader reader = command.ExecuteReader(); // i
get the error here
while (reader.Read())
{
Console.WriteLine(reader[0].ToString());
}
reader.Close();
}
}
}
}