Teaching experience: ADO.NET connection and disconnection

zhaozj2021-02-16  57

There are a lot of books and articles about ADO.NET. It is mainly used here to make two small examples to give students a demonstration, compare the connection and disconnection of ADO.NET, programmers generally don't like to be preaching, below Speak with code:

Connection:

SqlConnection SQLCONN = New SQLCONNECTION ("Server = .; data = pubs; user ID = sa; password =;"); sqlcommand sqlcomm = new SQLCommand ("Select * from authors", sqlconn); // Operation is open and disconnected Database between sqlconn.open (); sqldataareader dr = sqlcomm.excuteReader (); while (tr.read ()) {for (int i = 0; i

Disconnection

SqlConnection sqlConn = new SqlConnection ( "server = .; database = pubs; user id = sa; password =;"); SqlDataAdapter adapter = new SqlDataAdapter ( "select * from authors", sqlConn); // update commands for automatic production Sqlcommandbuilder CB = New SqlcommandBuilder (adapter); sqlconn.open (); DataSet DS = New DataSet (); Adapter.Fill (DS); sqlconn.close (); // Processing Data After opening and closing FOR (INT i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-19006.html

New Post(0)