C# textbox输入实现查询,通过gridview显示的问题
现在文本框TextBox1中输入信息,然后点按钮查询,可是页面中在文本框中输入内容点按钮,什么都没有出来?这是为什么啊?代码在下面privatevoidbutton1_C...
现在文本框TextBox1中输入信息,然后点按钮查询,可是页面中在文本框中输入内容 点按钮
,什么都没有出来? 这是为什么啊?
代码在下面
private void button1_Click(object sender, EventArgs e)
{
string con = "Data Source=HIPHOR;Initial Catalog=运动会成绩名次管理系统;Integrated Security=True";
SqlConnection connection = new SqlConnection(con);
connection.Open();
string strsql = "select * from ydy where ydy_bj='"+TextBox1.Text+"'";
SqlDataAdapter da = new SqlDataAdapter(strsql, connection);
DataSet ds=new DataSet();
da.Fill(ds,"a");
GridView1.DataSource = ds.Tables["a"];
GridView1.DataBind();
connection.Close();
}
前台代码如下:
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" Text="Button" /> <br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</form>
</body> 展开
,什么都没有出来? 这是为什么啊?
代码在下面
private void button1_Click(object sender, EventArgs e)
{
string con = "Data Source=HIPHOR;Initial Catalog=运动会成绩名次管理系统;Integrated Security=True";
SqlConnection connection = new SqlConnection(con);
connection.Open();
string strsql = "select * from ydy where ydy_bj='"+TextBox1.Text+"'";
SqlDataAdapter da = new SqlDataAdapter(strsql, connection);
DataSet ds=new DataSet();
da.Fill(ds,"a");
GridView1.DataSource = ds.Tables["a"];
GridView1.DataBind();
connection.Close();
}
前台代码如下:
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="button1" runat="server" Text="Button" /> <br />
<br />
<br />
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</form>
</body> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询