Learn about the inside of ADO--reading notes

Source: Internet
Author: User

The following is from the book "Proficient in C # and. NET 4.0 Database development-Tsinghua University Press" If you have clear spring please contact delete

"ADO is a group of direction. NET programmers expose the interfaces of the data Access Service (including classes, structs, interfaces, and so on) to ADO. NET provides a rich set of components for creating distributed data sharing applications to the MIC SQL Ser

Provides consistent access to data sources such as XML and data sources exposed through OLE DB and XML.

"ADO. NET is just a component, yes. NET Framework, there is a set of tools and class libraries that comprise "

The program provided by ADO includes several core classes that abstract the interfaces that the database needs to implement to access individual operations in ADO.

Learn about ADO. NET Related class Library

Core class base class description

Conntion DbConnection establishes and represents a connection to the database server

Command DbCommand to represent and execute specific database commands

DataReader DbDataReader represents a data stream that fetches data from the database server in a read-only way

DataAdapter DbDataAdapter populating the dataset with data from the database server or updating the database server for changes to the dataset

Transaction dbtransaction Login Transaction on database server

Commandbuild DbCommandBuilder automatically generates database commands to execute for DataAdapter

Connectionstringbuilder Dbconnectionstringbuilder automatically generates the database commands that need to be executed for DataAdapter, and the parameters of the commands are set.

Parameter DbParameter Define the input, output, return values, and other parameters of the database command

The DataTable class represents a data table that can typically be created in 2 ways

One is obtained from the database through database operations:

The second is to create through the DataTable's constructor function

DataTable (string name) creates a table named name

DataColumn (String Name,type ty) creates a column named name and a data column of type Ty

Example traversing a DataTable record

static void Main (string[] args)

{

DataTable DT =createusertable ()

Printdatatablebyname (DT)

Printdatatablebycolumn (DT)

}

public static DataTable createusertable ()

{

DataTable DT =new DataTable ("Users");

DataColumn Col =new dtacolumn ("Username", typeof (String));

Col. caption= "Name";

Col.  Allowdbnull=false; The set column cannot be empty

Dt.column.add (COL);

Dt.column.AddRange ()

New datacolumn[]{

New DataColumn ("Age", typeof (int),)//column

New DataColumn ("Mobile", typeof (String)}),

DataRow Row=dt. NewRow ()

row["UserName"]= "Zhang San";

row["Age"]=20;

row["Mobile"]= "1351111122222"

Dt. Rows.Add (row);

}

public void Printdatatablebyname (Datatablee dt)

{

System.Console.WriteLine ("Printdatatablebyname ():");

foreach (DataRow row in dt. Rows)

{

System.Console.Write ("{0}\t, row[" UserName "]");

System.Console.Write ("{0}\t,row[" age "]");

System.Console.Write ("{0}\t", row["Mobile"])

System.writeline ();

}

}

public static void Printdatatablebycolumn (DataTable dt)

System.Console.WriteLine ("Printdatatablebycolumn ():");

foreach (DataRow row in dt. Rows)

{

Foreeach (DataColumn col in dt. Columns)

{

System.Console.Write ("{0}\t,row[col]);

}

System.Console.WriteLine ();

}}

Learn about the ADO database operations class

DbConnection class: Represents a connection to a database server, which is the base class for all data connection classes, providing methods for opening and closing database connections, performing transactions, creating commands, and so on.

DbCommand class: Represents an executable SQL command that can be a generic SQL command such as SELECT, Delete, and so on

DbParameter class: Represents a parameter in a SQL command,

DbDataReader class: Represents a read-only forward data reader.

DbDataAdapter class: Represents a database adapter,

Learn about the inside of ADO--reading notes

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.