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();
}