先贴代码protected void Button1_Click(object sender, EventArgs e)
    {        string cx = "select * from shetuanxinxi where sno='" + TextBox1.Text + "'";
            SqlDataSource1.SelectCommand = cx;
            this.GridView1.EmptyDataText = "查询无结果,请重新输入查询条件!";
        GridView1.DataSourceID = "SqlDataSource1";        GridView1.DataBind();
    }如上面,代码,我在文本框输出查询条件,是可以查询的,但我想查询数据库里 编号>1的却查不了。
意思是 我在文本框里 输入>1 显示错误。
要怎么样才能查询呢?GridView

解决方案 »

  1.   

    拼起来的sql语句不对,自然无法查询了。不应该这么做,你可以放个下拉框,里面放几个选项:空,大于,小于……之类的。
    根据下拉框的选择值组成sql语句。
      

  2.   

    你觉得这是一条语法正确的sql么
    select * from shetuanxinxi where sno = '>1'select * from shetuanxinxi where sno >1
    另外,
    学会调试,这样你就知道程序有什么问题了
    到www.51aspx.com下一个3层留言板之类的项目,学习学习~
      

  3.   

    string cx = "select * from shetuanxinxi where sno" + DropDownList1.SelectedValue + "'" + TextBox1.Text + "'";
    下拉框里的选项的Value可以是
    =
    <
    >
    <=
    >=
      

  4.   

    SQL语句问题,如果查询出错你可以到数据库里输入那查询语句看看有没有结果,学会自己调试!
      

  5.   

    我还想问下,如果我设置了下拉  有 =, < ,>  但只是能查编号,如果输入名称呢? 
      

  6.   

    组合查询需要再放文本框之类的控件,类似于论文查询,你要做的就是把这些东东的值拼成一个合法的sql。
      

  7.   


     protected void Button1_Click(object sender, EventArgs e)
        {
            string cx1 = "select * from shetuanxinxi where sno" + DropDownList1.SelectedValue + "'" + TextBox1.Text + "'";
                SqlDataSource1.SelectCommand = cx1;
                string cx2 = "select * from shetuanxinxi where sname ='" + TextBox2.Text + "'";
                SqlDataSource1.SelectCommand = cx2;
                string cx3 = "select * from shetuanxinxi where stype ='" + TextBox3.Text + "'";
                SqlDataSource1.SelectCommand = cx3;
                this.GridView1.EmptyDataText = "查询无结果,请重新输入查询条件!";
            GridView1.DataSourceID = "SqlDataSource1";        GridView1.DataBind();
        }这样查询不了