C#Winform内存加载多条件查询数据

来源:互联网 发布:上海软件开发 编辑:程序博客网 时间:2024/06/07 02:02
 string gl_roomid = "";        int gl_row_index = -1;        DataTable gl_dt = new DataTable();        DataTable dt = new DataTable();        

 protected void LoadData()        {            gl_dt = dt.Copy();             gl_dt.Columns["price"].DataType = Type.GetType("System.Decimal");            string roomid = this.txtRoomid.Text.ToString();            string price_start = this.txtPrice_Start.Text.ToString();            string price_end = this.txtPrice_End.Text.ToString();            if (roomid.Length > 0)            {                DataRow[] rows = gl_dt.Select(" roomid='" + roomid + "'");                if (rows.Count() > 0)                {                    gl_dt = rows.CopyToDataTable();                }                else                {                    gl_dt.Clear();                }            }            if (price_start.Length > 0)            {                 DataRow[] rows = gl_dt.Select(" price >=" + price_start + " ");                 if (rows.Count() > 0)                 {                     gl_dt = rows.CopyToDataTable();                 }                 else                 {                     gl_dt.Clear();                 }            }            if (price_end.Length > 0)            {                DataRow[] rows = gl_dt.Select(" price <=" + price_end + " ");                if (rows.Count() > 0)                {                    gl_dt = rows.CopyToDataTable();                }                else                {                    gl_dt.Clear();                }            }                this.dataGridView1.DataSource = gl_dt;                  }

0 0