SQL syntax and ADO summary

Source: Internet
Author: User

First, SQL syntax

1. Query Statement Select

SELECT * FROM table name where query condition

2. Delete statements

Delete table name where delete condition

3. INSERT statement Inserts

Insert into table name (Field 1, Field 2) VALUES (' Value 1 ', ' Value 2 ')

4. Modify Statement Update

Update table name Set field = new value where modify condition

5. SQL statement Operations Database and table

drop table name//delete data table

Create DATABASE Database name//databases created

Drop database name//delete data bitter

ALTER TABLE name add field name data type//data table added field

ALTER TABLE Name drop column field name//Data table Delete field

ALTER TABLE name ALTER COLUMN field name new data type//modify field data type


Second, the use of the ADO object


1. SqlConnection class: Create a Database link object

SqlConnection conn=new SqlConnection ("server= server name; uid= user; pwd= password; database= database name");


2. SqlCommand class: The object that executes the SQL statement

SqlConnection conn=new SqlConnection ("server= server name; uid= user; pwd= password; database= database name");

String cmdstr= "select * from Student";

SqlCommand cmd=new SqlCommand (Cmdstr,con);


3. SqlDataReader class: Create an object that queries one or more data

SqlConnection conn=new SqlConnection ("server= server name; uid= user; pwd= password; database= database name");

String cmdstr= "select * from Student";

SqlCommand cmd=new SqlCommand (Cmdstr,con);

SqlDataReader Reader=cmd. ExecuteReader ();

4. SqlDataAdapter class: Create an object to retrieve and persist data

SqlConnection conn=new SqlConnection ("server= server name; uid= user; pwd= password; database= database name");

String cmdstr= "select * from Student";

SqlCommand cmd=new SqlCommand (Cmdstr,con);

SqlDataAdapter Adapter=new SqlDataAdapter (CMD);


5. DataSet class: Create a local data store object

SqlConnection conn=new SqlConnection ("server= server name; uid= user; pwd= password; database= database name");

String cmdstr= "select * from Student";

SqlCommand cmd=new SqlCommand (Cmdstr,con);

SqlDataAdapter Adapter=new SqlDataAdapter (CMD);

DataSet ds=new DataSet ();

Adapter. Fill (DS);

This article from the "Search in the Wind" blog, declined to reprint!

SQL syntax and ADO summary

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.