[我的ASP.net学习历程]DataBase Settion(6)

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

{

/// <summary>

/// WebForm1 的摘要说明。

/// </summary>

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)

{

// 在此处放置用户代码以初始化页面

string strSql = "SELECT ID,Username,Password,Content,Email,Homepage FROM Table_1";

string connectionString = "Server=(local);User ID=sa;Pwd=testPass;Database=TestDb;Connect Timeout=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:该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

TableRow tr = e.Item;

lblChoise.Text = "您选择的用户是:" + tr.Cells[1].Text;

lblChoise.Text = lblChoise.Text + " 密码是:" + tr.Cells[2].Text;

lblChoise.Text = lblChoise.Text + " 内容是:" + tr.Cells[3].Text;

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航