почему я не могу экспортировать Gridview, чтобы преуспеть, когда моя 'строка sql' с переменной "+ sqlwhere +" - PullRequest
0 голосов
/ 05 июля 2019

когда у меня есть код в «строке SQL» с переменной «+ sqlwhwew +», Excel не может показать любое содержимое, кроме этого случая, другие дела в порядке.

Если я удалю "+ sqlwhere +", он может экспортироваться в Excel.

открытый частичный класс ExportEmployeeReport: BPage {

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        BindData();

    }
    TWDKM.Web.Common.ExportToExcel(this, "report");
}
protected void rptPremissionList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

    }
}
private void SplitPage1_GoToPage(object sender, EventArgs e)
{
    BindData();
}

protected DataSet CreateDataSource(string SQL)
{
    string connstr = System.Configuration.ConfigurationManager.ConnectionStrings["DataAccessQuickStart1"].ConnectionString;
    try
    {
        DataSet ds = new DataSet();
        SqlConnection conn = new SqlConnection(connstr);
        SqlCommand cmd = new SqlCommand(SQL, conn);
        cmd.CommandTimeout = 0;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        return ds;
    }
    catch (Exception ErrorInfo)
    {
        return null;
    }
}

protected void BindData()
{
    string DDD = "5010";
    string CCC = "9511";
    string AAA = "9501";
    string BBB = "9531";
    string sqlwhere = string.Empty;
    sqlwhere += @"  (o.DTYCD2 not LIKE ''%" + AAA + @"%''
)";
    sqlwhere += @" AND (DTYCD2 not LIKE ''%" + BBB + @"%''
)";
    sqlwhere += @" AND (DTYCD2 not LIKE ''%" + CCC + @"%''
)";
    sqlwhere += @" AND (DTYCD2 not LIKE ''%" + DDD + @"%''
)";



    string SQL = "select  o.DEPTNM as DEPTNM,count(distinct p.UserAccount) as number,round(cast(count(p.UserAccount) AS FLOAT)/nullif( count(o.userid),0),2) as number1,count(distinct case when" **+ sqlwhere +** " then p.UserAccount end) as number2  from V_EmployeeKm as o left join T_UserLog as p    on p.UserAccount=o.USERID  group by o.DEPTNM";

    DataSet ds = CreateDataSource(SQL);

    //string SQL = "select  dbo.F_GetUserNameById(UserID) AS Name,dbo.F_Get_EmpyDeptbyID(UserID) AS Dept,Year,(Select MovieClassName from T_ELearnMovieClass where MovieClassID=MovieClassFK) AS MovieClass,sum(TotalTime) as TotalTime from T_MoviePlayedTime group by MovieClassFK,Year,UserID order by Name , Dept ,Year";

    if (ds != null && ds.Tables[0].Rows.Count>0)
    {
        this.rptPremissionList.DataSource = ds.Tables[0];
        this.rptPremissionList.DataBind();
    }

}

}

показывает ошибку, что имя в Excel не совпадает, а содержимое в Excel отсутствует. помогите пожалуйста как это исправить

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...