如我想查ID号大于5的所有结果,在ID一栏输入'>5',select出所有结果,该c#与sql如何写比较好,谢谢!

解决方案 »

  1.   

    string sql = "select * from tablename where id"+this.TextBox1.Text;
      

  2.   

    string strSQL = "SELECT * FROM table WHERE ID" + ">5"
      

  3.   

    string strSql="select * from table where ID>5";
      

  4.   

    正解
    ID可以=5,也可以>5,也可以<5
      

  5.   

    <asp:DropDownList ID="ddlCondition" runat="server">
                <asp:ListItem Value="=">=</asp:ListItem>
                <asp:ListItem Value=">">></asp:ListItem>
                <asp:ListItem Value="<"><</asp:ListItem>
                <asp:ListItem Value=">=">>=</asp:ListItem>
                <asp:ListItem Value="<="><=</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    用选的吧
    string sql = "select * from tablename where id"+this.ddlCondition.SelectedValue+this.TextBox1.Text;
      

  6.   


    string sql = "select * from tablename where id"+this.TextBox1.Text; 
      

  7.   

    string strSql="select * from table where ID>=5";
      

  8.   

    6楼的做法不错,把你的规则(大于等于)放在一个DropDownList里,你自己选择