不用sqldatasource,自己编写sql语句绑定gridview

  //构见sdsall的SQL命令字符串

        var str1="SELECT * FROM [cxsq] ";

        if (ddlsqs.Value != "全省")

            str1 = str1 + " where [xiaqu]=" + "'" + ddlsqs.Value + "'";


        if (ddlxsq.Value != "全部县市区")

            str1 = str1 + " and [xsq]=" + "'" + ddlxsq.Value + "'";

 

        if (ddlstatus.Value != "全部")

            str1 = str1 + " and [status]=" + "'" + ddlstatus.Value + "'";


        if (ddlyear.Value != "全部")

            str1 = str1 + " and CONVERT(varchar(4), appdate, 23) =" + "'" + ddlyear.Value + "'";


        str1 = str1 + " and [kind]='改名'";

 

        string connString = "server=.; uid=skdb; pwd=skdb; database=skdb";
        SqlConnection conn = new SqlConnection(connString);
        SqlDataAdapter sda = new SqlDataAdapter(str1, conn);

        DataTable result = new DataTable();
      
        sda.Fill(result);

        gvsqls.DataSource = result;
        gvsqls.DataBind();
 

你可能感兴趣的:(职场,休闲,手动绑定gridview)