This article supporting source code
We all know that the normal operation of the system without the database operation of this piece, and it has a decisive role in this system, it can be said that without its operating system will not be able to run, so in this section of the course, specifically for the operation of the database to speak out, so that everyone easier to understand the course behind.
OK, get to the point ...
First, let's create a new class with the following methods:
Open the last lesson of our new Questionnairesystem project, right-click the project name, select "Add" to "Class" in the dialog box that appears, select "Class" in the "Add New Item" pop-up, and enter "Dboperate" in the name below, and click "Add", As shown in Figure 4-1 below:
OK, so our dboperate class files are created, but the inside is still blank, so we will work together to write the appropriate method.
Now the first thing we need to do to manipulate the database is to write a way to open the database. Because we are using the ACCESS2003 database, we have to first use a System.Data.OleDb class library and a System.Data class library, method: The top of the new Dboperate file, that is, write a few using ... Place, write the following:
using System.Data;
using System.Data.OleDb;
Second, we need to define the following two database operations objects:
protected OleDbConnection dbconn;//定义数据库连接对象
protected OleDbCommand dbcomm = new OleDbCommand();//定义数据库操作对象