主题:关于搜索条的问题
今天在做搜索条的时候碰到了一点问题
这个搜索条的HTML代码:
<asp:Label ID="Label1" runat="server" Text="查询条件"></asp:Label>
<asp:DropDownList ID="ddlSelectCondition" runat="server">
<asp:ListItem Selected="True">请选择</asp:ListItem>
<asp:ListItem Value="productID">商品ID</asp:ListItem>
<asp:ListItem Value="productName">商品名称</asp:ListItem>
<asp:ListItem Value="productTypeName">商品类别</asp:ListItem>
<asp:ListItem Value="isHot">是否热门</asp:ListItem>
<asp:ListItem Value="isRecommend">是否推荐</asp:ListItem>
<asp:ListItem Value="isBargain">是否特价</asp:ListItem> </asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="关键字"></asp:Label>
<asp:TextBox ID="txtKey" runat="server"></asp:TextBox>
<asp:Button ID="btnSelect" runat="server" OnClick="btnSelect_Click" Text="查询" />
这个是搜索的代码:
protected void btnSelect_Click(object sender, EventArgs e)
{
con.Open();
string sqlstrSelect = "select * from vb_ProductInfo where " + ddlSelectCondition.SelectedValue + "like '%" + txtKey.Text.Trim() + "%'";
SqlDataAdapter sdaSelect = new SqlDataAdapter(sqlstrSelect, con);
DataSet dsSelect = new DataSet();
sdaSelect.Fill(dsSelect);
gvManageProduct.DataSource = dsSelect;
gvManageProduct.DataBind();
Response.Write(ddlSelectCondition.SelectedValue);
con.Close();
}
这个是视图的代码:
CREATE VIEW dbo.vb_ProductInfo
AS
SELECT dbo.T_Product_Info.productID, dbo.T_ProductType.productTypeID,
dbo.T_ProductType.productTypeName, dbo.T_Product_Info.productName,
dbo.T_Product_Info.introduction, dbo.T_Product_Info.ourPrice,
dbo.T_Product_Info.image, dbo.T_Product_Info.isHot,
dbo.T_Product_Info.isRecommend, dbo.T_Product_Info.isBargain
FROM dbo.T_Product_Info INNER JOIN
dbo.T_ProductType ON
dbo.T_Product_Info.productTypeID = dbo.T_ProductType.productTypeID
我在运行的时候搜索条件选是否推荐,关键字填“是”
点搜索的时候就报错“第 1 行: '%是%' 附近有语法错误。”
请问错在哪里,应该怎么改正,谢谢!
这个搜索条的HTML代码:
<asp:Label ID="Label1" runat="server" Text="查询条件"></asp:Label>
<asp:DropDownList ID="ddlSelectCondition" runat="server">
<asp:ListItem Selected="True">请选择</asp:ListItem>
<asp:ListItem Value="productID">商品ID</asp:ListItem>
<asp:ListItem Value="productName">商品名称</asp:ListItem>
<asp:ListItem Value="productTypeName">商品类别</asp:ListItem>
<asp:ListItem Value="isHot">是否热门</asp:ListItem>
<asp:ListItem Value="isRecommend">是否推荐</asp:ListItem>
<asp:ListItem Value="isBargain">是否特价</asp:ListItem> </asp:DropDownList>
<asp:Label ID="Label2" runat="server" Text="关键字"></asp:Label>
<asp:TextBox ID="txtKey" runat="server"></asp:TextBox>
<asp:Button ID="btnSelect" runat="server" OnClick="btnSelect_Click" Text="查询" />
这个是搜索的代码:
protected void btnSelect_Click(object sender, EventArgs e)
{
con.Open();
string sqlstrSelect = "select * from vb_ProductInfo where " + ddlSelectCondition.SelectedValue + "like '%" + txtKey.Text.Trim() + "%'";
SqlDataAdapter sdaSelect = new SqlDataAdapter(sqlstrSelect, con);
DataSet dsSelect = new DataSet();
sdaSelect.Fill(dsSelect);
gvManageProduct.DataSource = dsSelect;
gvManageProduct.DataBind();
Response.Write(ddlSelectCondition.SelectedValue);
con.Close();
}
这个是视图的代码:
CREATE VIEW dbo.vb_ProductInfo
AS
SELECT dbo.T_Product_Info.productID, dbo.T_ProductType.productTypeID,
dbo.T_ProductType.productTypeName, dbo.T_Product_Info.productName,
dbo.T_Product_Info.introduction, dbo.T_Product_Info.ourPrice,
dbo.T_Product_Info.image, dbo.T_Product_Info.isHot,
dbo.T_Product_Info.isRecommend, dbo.T_Product_Info.isBargain
FROM dbo.T_Product_Info INNER JOIN
dbo.T_ProductType ON
dbo.T_Product_Info.productTypeID = dbo.T_ProductType.productTypeID
我在运行的时候搜索条件选是否推荐,关键字填“是”
点搜索的时候就报错“第 1 行: '%是%' 附近有语法错误。”
请问错在哪里,应该怎么改正,谢谢!