"select * from Book where DropDownList1.SelectedValue='"+TextBox1.Text.Trim()+"'"
你的sql语句
where DropDownList1.SelectedValue....
你有一个字段叫DropDownList1.SelectedValue吗????
你的sql语句
where DropDownList1.SelectedValue....
你有一个字段叫DropDownList1.SelectedValue吗????
"select * from Book where 某一个字段值比如bookname='"+TextBox1.Text.Trim()+"'"
<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的字段
改成:
"select * from Book where "+Dropdownlist2.SelectedItem.Value+"='"+TextBox1.Text.Trim()+"'"
<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();
正解
"select * from Book where "+DropDownList1.SelectedValue+"='"+TextBox1.Text.Trim()+"'"