Perform simple operations on Ado.net databases with C #

Source: Internet
Author: User

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";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.