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

xiaoxiao2021-03-06  52

Using system;

Using system.collections;

Using system.componentmodel;

Using system.data;

Using system.drawing;

Using system.Web;

Using system.Web.SessionState;

Using system.Web.ui;

Using system.Web.ui.webcontrols;

Using system.Web.ui.htmlcontrols;

Using system.data.sqlclient;

Namespace _172._24._17._134

{

///

/// WebForm1 summary description.

///

Public class Webform1: System.Web.ui.page

{

Protected system.web.ui.webcontrols.label lblchoise;

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

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

{

/ / Place the user code here to initialize the page

String strsql = "SELECT ID, Username, Password, Content, Email, HomePage from Table_1";

String connectionString = "server = (local); user ID = sa; pwd = testpass; database = testdb; connection = testdb; connection = test = 5;

SqlConnection Conn = New SqlConnection (Connectionstring);

Sqlcommand cmd = new SQLCOMMAND (strsql, conn);

cmd.connection.open ();

DataSet DS = New Dataset ();

Sqldataadapter Da = new SqlDataAdapter ();

Da.selectCommand = CMD;

Da.fill (DS, "Table");

DataGrid1.datasource = ds.tables ["Table"]. DefaultView;

DataGrid1.databind ();

Ds.clear ();

Da.Dispose ();

cmd.connection.close ();

cmd.connection.dispose ();

}

#Region Web Form Designer Generated Code

Override protected void oninit (Eventargs E)

{

//

// Codegen: This call is necessary for the ASP.NET Web Form Designer.

//

InitializationComponent ();

Base.onit (E);

}

///

/// Designer supports the required method - do not use the code editor to modify

/// This method is content.

///

Private vidinitiRizeComponent ()

{

This.DataGrid1.itemCommand = new system.web.ui.webcontrols.dataGridCommandeventhandler (THISDATAGRID1_ITEMCOMMAND);

This.Load = new system.eventhandler (this.page_load);

#ndregion

Private void DataGrid1_itemCommand (Object Source, System.Web.ui.WebControls.DataGridCommandeventArgs E)

{

TableRow Tr = E.Item;

LBlchoise.Text = "The user you choose is:" tr.cells [1] .text;

lblchoise.text = lblchoise.text "Password is:" Tr.cells [2] .Text;

lblchoise.text = lblchoise.text "The content is:" tr.cells [3] .Text;

}

}

}

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

New Post(0)