The code for using the C # link to ACCESS is as follows: usingSystem. data; usingSystem. data. oleDb; OleDbConnectionconnectionnewOleDbConnection (ProviderMicrosoft. jet. OLEDB.4.0; + performancec: DbViewtysql. mdb); open the database connection. open (); MessageB
The code for using C # To link to ACCESS is as follows: using System. data; using System. data. oleDb; OleDbConnectionconnection = new OleDbConnection (Provider = Microsoft. jet. OLEDB.4.0; + DataSource = C: \ DbView \ tysql. mdb); // open the database connection. open (); MessageB
The code for using the C # link to ACCESS is as follows:
Using System. Data;
Using System. Data. OleDb;
OleDbConnection connection = new OleDbConnection ("Provider = Microsoft. Jet. OLEDB.4.0;" +
"Data Source = C: \ DbView \ tysql. mdb ");
// OpenDatabaseConnection
Connection. Open ();
MessageBox. Show ("OpenDatabaseConnection successful ");
// CloseDatabaseConnection
Connection. Close ();
MessageBox. Show ("DisabledDatabaseConnection successful ");
AccessDatabaseAn additional namespace needs to be imported. Therefore, the first two using commands are required!
"Provider = Microsoft. Jet. OleDb.4.0;" is the index data Provider. Here we use the Microsoft Jet Engine, which is the Data Engine in Access. asp.net relies on this and Access.DatabaseConnected.
"Data Source = C: BegASPNETNorthwind. mdb" indicates the location of the Data Source. Its standard format is "Data Source = MyDrive: MyPathMyFile. MDB ".
Ps:
1. If you want to connectDatabaseThe file and the current file are in the same directory and can be connected using the following method:
StrConnection + = "Data Source = ";
StrConnection + = MapPath ("Northwind. mdb ");
In this way, you can write a lot of things!
3. Note that parameters in the connection string must be separated by semicolons.
"OleDbConnection objConnection = new OleDbConnection (strConnection);" this sentence uses the defined connection string to create a link object.DatabaseWe have to deal with this object.
"ObjConnection. Open ();" this is used to Open the connection. At this pointDatabaseThe connection is complete. For other operations (insert, delete...), see related books.
C # query ACCESSDatabase:
1 int num = 0; // Number of Members
2 string message = ""; // the pop-up result message.
3 // SQL statement used for query
4 string SQL = "SELECT COUNT (*) FROM Orders ";
5
6 try
7 {
8 connection. Open (); // OpenDatabaseConnection
9 OleDbCommand command = new OleDbCommand (SQL, connection );
10 // Execute SQL query
11 num = <