"select * from Book where DropDownList1.SelectedValue='"+TextBox1.Text.Trim()+"'"
你的sql语句
where DropDownList1.SelectedValue....
你有一个字段叫DropDownList1.SelectedValue吗????

解决方案 »

  1.   

    应该是:
    "select * from Book where 某一个字段值比如bookname='"+TextBox1.Text.Trim()+"'"
      

  2.   

    有啊~~ 
    <asp:ListItem Value="BookID">按书号</asp:ListItem>
    <asp:ListItem Value="BookAuthor">按作者</asp:ListItem>
    asp:ListItem Value="BookName">按书名</asp:ListItem>
    <asp:ListItem Value="BookKind">按类别</asp:ListItem>
    <asp:ListItem Value="BookPublish">按出版社</asp:ListItem>BookID,BooKAuthor...都是Book的字段
      

  3.   

    首先你得设好每个ListItem的Value,然后在select语句里根据这个Value选择
      

  4.   

    "select * from Book where DropDownList1.SelectedValue='"+TextBox1.Text.Trim()+"'"
    改成:
    "select * from Book where "+Dropdownlist2.SelectedItem.Value+"='"+TextBox1.Text.Trim()+"'"
      

  5.   

    我已经设了了啊 而且也是根绝这个来选择的~~
    <asp:ListItem Value="BookID">按书号</asp:ListItem>
    <asp:ListItem Value="BookAuthor">按作者</asp:ListItem>
    asp:ListItem Value="BookName">按书名</asp:ListItem>
    <asp:ListItem Value="BookKind">按类别</asp:ListItem>
    <asp:ListItem Value="BookPublish">按出版社</asp:ListItem>
    SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
    SqlDataAdapter cmd=new SqlDataAdapter("select * from Book where DropDownList1.SelectedValue='"+TextBox1.Text.Trim()+"'",con);
    DataSet ds=new DataSet();
    cmd.Fill(ds,"Book");
    DataGrid1.DataSource=ds.Tables["Book"].DefaultView;
    DataGrid1.DataBind();
      

  6.   

    "select * from Book where "+DropDownList1.SelectedValue='"+TextBox1.Text.Trim()+"'"
      

  7.   

    linfuguo(小林子) 
     正解
      

  8.   

    错了!
    "select * from Book where "+DropDownList1.SelectedValue+"='"+TextBox1.Text.Trim()+"'"