Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8676

Re: Export to PDF from populated c# Dataset without Database connection

$
0
0

Not that hard to do... if multiple tables are used you may need to add them also.

 

private void DataSet1_Click(object sender, EventArgs e)
{
    //CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    ISCDReportClientDocument rcd;

    rcd = rptClientDoc;
    rptClientDoc = rpt.ReportClientDocument;

    System.Data.DataSet thisDataSet = new System.Data.DataSet();

    string sqlString = @"SELECT top 10*  FROM  ""xtreme"".""dbo"".""Financials"" ""Financials""";


    System.Data.OleDb.OleDbConnection oleConn = new System.Data.OleDb.OleDbConnection(connString);
    System.Data.OleDb.OleDbCommand cmd = oleConn.CreateCommand();
    cmd.CommandText = sqlString;

    System.Data.DataSet ds = new System.Data.DataSet();

    OleDbDataAdapter oleAdapter = new OleDbDataAdapter(sqlString, oleConn);
    //OleDbDataAdapter oleAdapter2 = new OleDbDataAdapter(sqlString2, oleConn);
    DataTable dt1 = new DataTable("Financials");
    //DataTable dt2 = new DataTable("Orders Detail");

    oleAdapter.Fill(dt1);
    //oleAdapter2.Fill(dt2);

    ds.Tables.Add(dt1);
    //ds.Tables.Add(dt2);
    // Saving to XML just o verify the data is valid. Open in CR Designer and set lcoation to the XML and then verify database to confirm it works
    ds.WriteXml("c:\\reports\\sc2.xml", XmlWriteMode.WriteSchema);

    // as long as the field names match exactly Cr has no problems setting report to a DS.
    try
    {
        rpt.SetDataSource(ds.Tables[0]);
        rpt.SetDataSource(ds);
    }
    catch (Exception ex)
    {
        MessageBox.Show("ERROR: Schema Mismatch. Error reported by CR: " + ex.Message);
    }

    MessageBox.Show("Data Source Set", "RAS", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

 

Don


Viewing all articles
Browse latest Browse all 8676

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>