[My ASP.NET Learning History] Database Settion (5)

xiaoxiao2021-03-06  53

Protected system.web.ui.webcontrols.dataGrid DataGrid1;

Private Void Page_Load (Object Sender, System.EventArgs E)

{

// Write a method:

// String Connectionstring = "Server = 172.24.17.134; user ID = sa; pwd = testpass; database = testdb";

// Writing 2:

// String Connectionstring = "Server = HD-Server; user ID = sa; pwd = testpass; database = testdb";

// Write three:

// String Connectionstring = "Server = (local); user ID = sa; pwd = testpass; database = testdb";

String Connectionstring = "Server = (local); user ID = sa; pwd = testpass; database = testdb";

String strsql = "SELECT * from TABLE_1";

SqlConnection Conn = New SqlConnection (Connectionstring);

Sqlcommand cmd = new SQLCOMMAND (strsql, conn);

cmd.connection.open ();

SqlDataReader DR = cmd.executeRead ();

DataGrid1.datasource = DR;

DataGrid1.databind ();

cmd.dispose ();

Dr.close ();

cmd.connection.close ();

cmd.connection.dispose ();

}

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

New Post(0)