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

C#根据dateTimePicker1和textbox查询到datagridview
C#根据开始时间dateTimePicker1、结束时间dateTimePicker2和textbox查询,是查询结果显示到datagridview1
 菜鸟求代码

------解决方案--------------------
string sql = string.Format("select * from tt where t1 between '{0}' and '{1}'", dateTimePicker1.Value, dateTimePicker2.Value);
            using (SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=123456;"))
            {
                conn.Open();

                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds);

                this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
            }

------解决方案--------------------
(出库单号 or 供应商 or 录入者 or 审核者 or 记账者 ='"+ txtgjz.Text+"'
这一大段错误了。
出库单号='"+ txtgjz.Text+"' or 供应商 ='"+ txtgjz.Text+"' ......
------解决方案--------------------
string sql="select * from tt where t1 between '"+dateTimePicker1.Value+"' and '"+dateTimePicker2.Value+"'"
 if(txtgjz.Text!="")
{
sql+=" And 出库单号='"+ txtgjz.Text+"' or 供应商 ='"+ txtgjz.Text+"' ......";
}