时间段的多条件查询,没有查询到数据
为什么我提交日期用时间段查询,但是没有查询到数据,但是确实是有符合的数据的,就是查询不出来,求解!!高手们
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "select * from v_tian_ok where 1=1";
if (txtTabh.Text != "")
sql += " and 提案編號 like N'%" + txtTabh.Text.ToString() + "%'";
if (txtTagh.Text != "")
sql += " and 提案者工號 like N'%" + txtTagh.Text.ToString() + "%'";
if (txtTjrq.Text != "" && txtTjrq2.Text != "")
sql += " and 提交日期 between N'%" + txtTjrq.Text.ToString() + "%' and N'%" + txtTjrq2.Text.ToString() + "%'";
if (txtTabm.Text != "")
sql += " and 提交部門 like N'%" + txtTabm.Text.ToString() + "%'";
if (txtTaxm.Text != "")
sql += " and 提案名稱 like N'%" + txtTaxm.Text.ToString() + "%'";
if (txtTajl.Text != "")
sql += " and 提案獎勵 like N'%" + txtTajl.Text.ToString() + "%'";
if (txtSlrq.Text !="" || txtSlrq2.Text != "")
sql += " and 受理日期 between N'%" + txtSlrq.Text.ToString() + "%' and N'%" + txtSlrq2.Text.ToString() + "%'";
SqlConnection con = new SqlConnection("Data Source=192.168.1.8;Initial Catalog=SITE;User ID=****;Password=****;");
SqlDataAdapter myApter = new SqlDataAdapter(sql, con);
DataSet myDS = new DataSet();
con.Open();
myApter.Fill(myDS);
GridView3.DataSource = myDS;
GridView3.DataBind();
//加入序号
int li_row;
int li_rowcount = GridView3.Rows.Count;
for (int i = 0; i < li_rowcount; i++)
{
li_row = i + 1;
GridView3.Rows[i].Cells[1].Text = li_row.ToString();
}
//无记录时表头也显示的一种解决方法
if (li_rowcount == 0)
{
lblbaocuo.Text = "没有找到任何记录";
}
con.Close();
}