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;
}
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' 附近)中指定了非布尔类型的表达式.
这一大段错误了。
出库单号='"+ txtgjz.Text+"' or 供应商 ='"+ txtgjz.Text+"' ......
if(txtgjz.Text!="")
{
sql+=" And 出库单号='"+ txtgjz.Text+"' or 供应商 ='"+ txtgjz.Text+"' ......";
}
根据你DropDownList的值 string sql = string.Format("select '{0}' from tt where time between tm1 and tm2",DropDownList.Text)