C # Link Database

Source: Internet
Author: User

A ADO (Access data Object)

. NET operations database a set of classes

    1. DataSet Data Set
    2. . NET Data provider (Provider) Core object:

Connection

Command

DataReader

DataAdapter

Two. Connection Connection object

1. Create:

SqlConnection conn = new SqlConnection ();

conn.connectionstring= ' link string '

Or:

SQLConnection Conn =new SQLConnection (link string);

2. Open the connection:

Conn.Open (); Open the database;

3. Link string:

(1) Address, database, account number, password

(2) Data Source = Server address, Initial catalog= database name, User id= account, password= password. or "server= server address; database= database name; uid= account; pwd= password. "(abbreviated)

Three Command execution Object

1. Syntax

SqlCommand comm=new SqlCommand ();

comm.commandtext= "SQL statement"//what SQL to execute;

Comm.command=conn//Where to execute

Shorthand:

SqlCommand comm=new SqlCommand (sql,conn);

2. Implementation

2.1 ExecuteScalar ()

2.2 ExecuteReader ()

2.3 Executenomquery ()

3.comm.executescalar ()

3.1 Command starts executing the target SQL statement and gets the results returned by the database

3.2 Get first row column in results only

3.3 Trial Conditions:

3.3.1 Aggregation function AVG (), MAX () ...

3.3.2 Query the value of a column based on a condition

Convert (Universal Transformation Example: convert.string convert.int32 ...)

C # Link Database

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.