读书人

C#依据dateTimePicker1和textbox查询到

发布时间: 2013-10-31 12:03:52 作者: rapoo

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+"' ......";
}

读书人网 >C#

热点推荐