2

コードを使用して Crystal レポートを作成して入力しようとしていますが、エラーが発生しました。 レポート にはテーブルがありませんが、DATASET からデータを抽出しようとすると、正確なデータが表示され、問題はありませんが、Crystal レポートでは機能しません。

コード:

protected void Dataset_load() 
{
    SqlConnection sqlcon = new SqlConnection(conStr);
    SqlCommand sqlCom = new SqlCommand("select * from Login", sqlcon);
    SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCom);
    DataSet ds = new DataSet("CRDataSet");

    try
    {
        sqlcon.Open();
        //sqlCom.ExecuteNonQuery();
        sqlDA.Fill(ds,"Login");

        ReportDocument rd = new ReportDocument();
        rd.Load(Server.MapPath("CrystalReport.rpt").ToString());
        rd.SetDataSource(ds.Tables["Login"]);
        CrystalReportViewer1.ReportSource = rd;


    }
    catch (Exception exc)
    {
        Response.Write(exc.Message);
    }
    finally 
    {
        sqlcon.Close();
    }
4

1 に答える 1

2

入力する前に、テーブルをデータセットに追加する必要があります。

DataSet ds = new DataSet("CRDataSet");
ds.Tables.Add(datatable);
于 2013-10-28T22:47:58.090 に答える