当前位置:编程学习 > C#/ASP.NET >>

asp.net数据库查询问题:如何实现点击某个按钮查询需要的信息.(代码已备,修改即可)

aspx代码:

<asp:Button ID="Button11" runat="server" OnClick="btnResult1_Click" Text="显示结果" />
<asp:Label ID="Label11" runat="server" Width="144px"></asp:Label><br />

cs代码:

protected void btnResult1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=localhost;uid=liwei1987;pwd=19870312;database=master";
conn.Open();

SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select 姓名 as 姓名,年龄 as 年龄,地址 as 地址 from emp";
cmd.Connection = conn;


SqlDataReader data;
data = cmd.ExecuteReader();
GridView1.DataSource = data;
GridView1.DataBind();

data.Close();
conn.Close();
conn.Dispose();
}

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,