ADO:
Data access Technology
is a link between C # and MSSQL.
Temporary data in memory can be written to the database via ADO
You can also extract data from the database into memory for program calls
Fundamentals of all data access technologies
Connection Database Basic format:
Requires two classes
1. Database Connection Class SqlConnection
2, database Operation class SqlCommand
Change and delete:
Keywords to use:
SqlConnection
SqlCommand
Cmd. ExecuteNonQuery ()
1. Connect to the database
Write the connection string, immediately think of 4 points to finish, 1, which server to connect to, 2, which database to connect, 3, connect user name, 4, password
String sql = "server=.; database=shujulianxi;user=sa;pwd=123456 "; Writing a connection string
Instantiate the data connection class, write the connection string to the constructor, and let the class be constructed to connect to the specified server and database
SqlConnection conn = new SqlConnection (SQL);
2. Set the actions to be done on the tables in the database
Create an action class for this library from a database that is already connected
SqlCommand cmd = conn. CreateCommand ();
Writing TSQL Statements
Cmd.commandtext = "Delete from Dianmian where name= ' cola '";
3. Perform operation
Conn. Open (); Database connection Open
cmd. ExecuteNonQuery (); //Database operation execution
Conn. Close (); Database connection shutdown
Check:
Keywords to use:
SqlConnection
SqlCommand
SqlDataReader
Cmd. ExecuteReader ()
1. Database connection class (connection string)
SqlConnection conn = new SqlConnection ("server=.; database=dianmian;user=sa;pwd=123456 ");
2, database operation class, through the above connection class build out
SqlCommand cmd = conn. CreateCommand ();
Query statements
Cmd.commandtext = "Select *from Dianmian";
3. Perform data operations
Conn. Open (); Database connection Open
SqlDataReader dr = cmd. ExecuteReader (); Call this method to query!!!!
Each time this method is executed, the pointer goes down one line, reads the data from the following line, and returns a false if there is no data below
while (Dr. Read ())
{
If the data is read, then the current reading of this line of data is placed in the Dr object, you can use two ways to remove the data
1. Use index-dr[index value]
Console.WriteLine (Dr[0] + "+ dr[1] +" "+ convert.todatetime (dr[2]). ToString ("yyyy year mm DD Day"));
2. Use column name-dr["column name"]
Console.WriteLine (dr["name"] + "" + dr["price"]+dr["Riqi"] + "");
}
Conn. Close (); Database connection shutdown
Data stored in the database is not necessarily able to be directly presented to the user to see, then the C # segment needs to be processed and then displayed
How to implement the ADO database access additions and deletions? and examples