Database access is the most common part of a program. With the introduction of C # and Ado.net, this operation becomes simpler. This article will demonstrate four of the most basic database operations.
Read the data. This includes a variety of data types: integer, String, and date type.
Write the data. As with reading data, we also need to write multiple types of data. This can be done through SQL statements.
Update or modify the data. We'll use the SQL statement again.
Deletes data. implemented in SQL.
All of these actions are based on the Microsoft Access 2000 database, but we need to make simple modifications to the connection string to use SQL or other ADO data.
Start operation
Before using the ADO class, we'll include the Ado.net namespace and some common data classes. Add the following code to the location where you want the database to operate. Its exact location should be after the namespace line, before the class declaration.
using System.Data; // State variables
using System.Data.ADO; // Database
using System.Globalization; // Date
You may also want to add parameters to the System.Data namespace, depending on the type of project you need. The compiled information of the code you add will remind you of this. To add an action for the System.Data namespace:
Right-click solution explorer--parameter option;
Select Add Parameters;
Select. NET frame bar;
Double-click the System.data.dll entry;
Select OK;
System.Data should appear in the Solution Explorer argument list.
Since the connection string is used in most operations, I recommend that you include it in the class you are using.
Note: The path to the database file in your program may not be the same as the following:
//Attributes
public const string DB_CONN_STRING =
"Driver={Microsoft Access Driver (*.mdb)}; "+
"DBQ=D:\\CS\\TestDbReadWrite\\SimpleTest.mdb";