How to Use OLE With Visual C
- 1). Open the Visual Studio software and the project you want to edit.
- 2). Add the OLE database libraries to the top of the file. You must include these libraries to connect using OLE. Copy and paste the following code to the top of the file:
using System.Data.OleDb; - 3). Create the connection to the database. In this example, a connection to an Access database is created using the Access Jet OLE libraries. Add the following code to create the connection:
string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.MDB";
OleDbConnection oleconn= null;
oleconn= new OleDbConnection(connect);
Replace "db.mdb" with the name of your own Access database. - 4). Query the database to retrieve the data using the OLE connection. The following code queries the database:
OleDbCommand cmd = new OleDbCommand("select * from customers",oleconn);
OleDbDataAdapter adapt = new OleDbDataAdapter(cmd);
oleconn.Open();
adapt.Fill(cmd);
Source...