You're asking about connecting your VC++ program to an Access database, right?
Alright, I'll tell you how to do it from the IDE, which is simpler; then using code.
You'll have to use an OleDbConnection. Set its "ConnectionString" property to your Access database. If you've never set this connection before, you'll need to create a new one. Simply choose <New Connection> from the connectionString property. The data link property window will show up; go to the "Provider" tab, select "Microsoft Jet 4.0 OLE DB Provider" from the list and click Next.
This will send you to the "Connection" tab, in the first edit box, select the Database. Then enter the User name and password in the other boxes. Click "Test Connection" (at the bottom) to make sure the connection is alright; then click OK.
To do it from code, here is a sample:
//Create the connection
OleDbConnection * conn = new OleDbConnection();
//Set the connection string
conn->ConnectionString =
S" Provider=Microsoft.Jet.OLEDB.4.0"
S"Data Source=C:\\temp\\myDatabase.mdb";
After this, everytime you need to read/write from/to the database, simply open the connection as such: conn->Open();
And don't forget to close it when done: conn->Close();
Hope this is what you were looking for.
|