我是菜鸟,不太会描述,直接上代码……
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView GridView1 = new GridView();
String x = TextBox1.Text;
String connectionString = ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string cmd = string.Format("select * from Table_1 where name='{0}' or age='{0}' or job='{0}'", x);
SqlDataAdapter adp = new SqlDataAdapter(cmd, con);
DataSet ds=new DataSet();
adp.Fill(ds);
this.GridView1.DataSourceID = null;
this.form1.Controls.Add(GridView1);
this.GridView1.DataSource =ds;
GridView1.DataBind();
con.Close();
} }
数据库名“new”,表“Label_1”,列“name、age、job”(varchar)。网页只有一个Textbox 一个Button 一个Gridview。
点击Button根据输入的内容查询数据库并选出相关列在Gridview中显示,显示完成后重新输入内容再点按钮没反应……应该再加几行什么……菜鸟求详细指点
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
GridView GridView1 = new GridView();
String x = TextBox1.Text;
String connectionString = ConfigurationManager.ConnectionStrings["newConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string cmd = string.Format("select * from Table_1 where name='{0}' or age='{0}' or job='{0}'", x);
SqlDataAdapter adp = new SqlDataAdapter(cmd, con);
DataSet ds=new DataSet();
adp.Fill(ds);
this.GridView1.DataSourceID = null;
this.form1.Controls.Add(GridView1);
this.GridView1.DataSource =ds;
GridView1.DataBind();
con.Close();
} }
数据库名“new”,表“Label_1”,列“name、age、job”(varchar)。网页只有一个Textbox 一个Button 一个Gridview。
点击Button根据输入的内容查询数据库并选出相关列在Gridview中显示,显示完成后重新输入内容再点按钮没反应……应该再加几行什么……菜鸟求详细指点
解决方案 »
- 急 !~~~~~~
- 如何把999999999变成999,999,999
- 在sql中添加一个用户,只能访问指定数据库中的指定的表,添加用户的步骤是怎样的?
- 从“企业管理器”中打开表时,先显示“没注册类”,然后显示“灾难性错误”
- 在建立check约束时的错误,大家帮我看看,谢谢
- 在下第一次发问:关于SQL触发器的问题,请高手回答!
- 存储过程翻页程序 .net上用sqldatareader对象存储返回的记录时 发生记录不符的情况
- 各位大侠帮帮忙,我的sql不能启动了!
- 请教一个sql语句的写法(难度比较大)
- how to view structure of a table ?command model
- SQLSERVER2008中 update 用法
- 如何一条sql分页,无标识无主键、不用Row_number、不用存储过程、不用游标
但是重新输入26的话就没反应了,
如果关闭调试然后重新调试一次,输入26,就会显示所有age为26的……
总之第一次搜索很顺利,但是再次搜索就没用了。