多条件动态查询求助!!!
代码: protected void Page_Load(object sender, EventArgs e)
{
//判断用户是否登录
if (Convert.ToString(Session["username"]) == "")
{
//如果未登录给出提示并返回登录页
Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
}
if (!IsPostBack)
{
Session["sql"] = "";
this.bind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
Response.Write("<script>window.open('详细信息.aspx?id=" + id + "','','width=450,height=450')</script>");
Response.Write("<script>location='javascript:history.go(-1)'</script>");
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string Sql = " ";
if (CheckBox1.Checked)
{
Sql = Sql + "and CompanyName like '%" + TN.Text + "%' ";
}
if (CheckBox2.Checked)
{
Sql = Sql + "and Type like '%" + PN.Text + "%' ";
}
Session["sql"] = Sql;
this.bind();
}
public void bind()
{
string strsql;
strsql = "select * from wzq_weixiu " + Session["sql"] + " order by id desc";
SqlConnection strcon = new SqlConnection(ConfigurationManager.ConnectionStrings["wzqConnectionString"].ConnectionString);
strcon.Open();
SqlDataAdapter sda = new SqlDataAdapter(strsql, strcon);
DataSet ds = new DataSet();
sda.Fill(ds, "search");
//设置GridView控件数据源
GridView1.DataSource = ds.Tables["search"];
//设置GridView主键
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["sql"] = "";
this.bind();
}
}
strsql = "select * from wzq_weixiu " + Session["sql"] + " order by id desc";这话有问题不知道怎么改,提示 在关键字 'and' 附近有语法错误。 求助大神!!