日期:2014-05-17  浏览次数:20723 次

动态查询数据的问题
这个是获得数据列表的拼接语句
 /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select [ID],[ProjectName],[ProjectSerils]");
            strSql.Append(" FROM ERPProject ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


前台查询语句

<asp:DropDownList ID="DropDownList" runat="server" Height="20px">
     <asp:ListItem Selected="True" Value="ProjectName">项目名称</asp:ListItem>
     <asp:ListItem Value="ProjectSerils">项目编号</asp:ListItem>
     <asp:ListItem Value="SuoShuKeHu">建设单位</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" Height="20px" Width="80px"></asp:TextBox>
                    
<asp:ImageButton
                        ID="ImageButton4" runat="server" ImageAlign="AbsMiddle" ImageUrl="../images/Button/BtnSerch.jpg"
                        OnClick="ImageButton4_Click" />
public void DataBindToGridview()
    {
        ZWL.BLL.ERPProject MyModel = new ZWL.BLL.ERPProject();
        String Proj = this.DropDownList.SelectedValue;
        Label1.Text = Proj;
        GVData.DataSource = MyModel.GetList("'Proj' Like '%" + this.TextBox1.Text + "%' order by ID desc");
        GVData.DataBind();
        LabPageSum.Text = Convert.ToString(GVData.PageCount);
        LabCurrentPage.Text = Convert.ToString(((int)GVData.PageIndex + 1));
        this.GoPage.Text = LabCurrentPage.Text.ToString();
    }


后台查询代码
public void DataBindToGridview()
    {
        ZW