ADO.NET link the idea of finishing the implementation of SQL

ado.net mainly access the data source data source is the database and database stuff inside
for different different ways to use ADO.NET database links


ADO database links first

and then perform CRUD

shut down

to clean up resources


to introduce namespace ---- locate the database (link string) ---- examples of linked objects


------ connection objects to establish a connection to open links -------


------- command command object, execute SQL. Close



Process

1: introduction of the namespace
a using System .data SqlClient;.

2: Link server / database / - Log

              server name ------> ----- database name> database account ---> password
string str = "Server = XKC; database = 1605"; UID = SA; pwd = 123 


. 3: examples of database connection object
sqlConnection conn = new sqlConnection (database login parameters used in [STR]; 4 total)

4: open database
conn . open ();

------------ establish good links above and open the database, then you execute the command.


1: Creating execute SQL objects
Sqlcommand cmd = new SqlCommand ();

2: SQL statement specifies to execute / or stored procedures
. Cmd the CommandText = "SELECT * from User";

. 3: determining the assignment above is the SQL / stored procedures or
cmd = .CommandType the CommandText;

----- With the above Links / open this person database [diplomat]
----- with the implementation of the above SQL objects, then you execute a SQL statement [owner] command

to specify the database link used by
SQL link ------ > chaining
cmd .Connection = connn;


declare a stream object, the SQL execution result to him
SqlDataReader sdr = cmd ExecuteReader (); .


read data stream
sdr.Read ()

a SDR = [ " name "]



end
Close stream object
sdr.Close ();

Close database connection
conn.Close ();

Transfer: https://www.cnblogs.com/gggg/p/5848698.html

Guess you like

Origin blog.csdn.net/cillent_boy/article/details/90900106