DataTable1TableAdapter中的GetData()查询:select * from Table1
下面是一个条件查询的方法
 private string GetWhere()
        {
            string wherestr = "where";
            if (textBox1.Text.Trim() != "")
            {
                wherestr += "test.EntryId like '%" + textBox1.Text.Trim() + "%'";
            }
            if (textBox2.Text.Trim() != "")
            {
                wherestr += "test.PrintPerson like '%"+textBox2.Text.Trim()+"%'";
            }
            if (textBox3.Text.Trim() != "")
            {
                wherestr += "type.TypeName like '%"+textBox3.Text.Trim()+"%'";
            }
            if (this.dateTimePicker1.Text.Trim() != "")
            {
                DateTime dt = new DateTime();
                if (DateTime.TryParse(this.dateTimePicker1.Text.Trim(), out dt) == true)
                {
                    wherestr += "and test.PrintDate >='" + dt.ToString("yyyy-MM-dd") + "00:00:00" + "'";
                    wherestr += "and test.PrintDate<='"+dt.ToString("yyyy-MM-dd")+"23:59:59"+"'";
                }
            }
            wherestr += "order by test.SeqId asc";
            return wherestr;        }
怎样把这个GetWhere方法返回的查询条件添加到GetData()里也加时连到select * from Table1后面?

解决方案 »

  1.   

    GetData() 这个函数不能改吗?
      

  2.   

    在GetData()函数里
    string sql = "select * from Table1" + GetWhere();
    这样不行吗?
      

  3.   

    你把查询放在hid中 然后点击按钮的时候传值就好了
      

  4.   

    GetData(string strwhere)
    {
      string sql=string.Format("select * from table where 1=1 {0}",strwhere)
    }  每个查询条件要加and  例如  "and test.EntryId like '%" + textBox1.Text.Trim() + "%'";执行  GetData( GetWhere() );
      

  5.   

    GetData是数据集中的查询语句 不是一个类的方法。不能改。
      

  6.   

    最多只能加 where条件查询 无法加参数
      

  7.   

    忘了说了是 C/S 不是BS
      

  8.   

    那你找找看 DataTable1TableAdapter 这个类里面有没有添加条件的方法,应该是有的,要不然这个类不完善,或者提供接口让你自己写
      

  9.   


    那就把GetWhere()返回结果添加上不可以么