ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1Report > Advanced Uses > Custom Data Sources > Using Your Own DataTable Objects

Using Your Own DataTable Objects

The main reason to use your own DataTable objects is in situations where you already have the object available, and want to save some time by not creating a new one. You may also want to implement security schemes or customize the object in some other way.

To use your own DataTable object, simply assign it to the RecordSet property before you render the report. For example:

      Visual Basic

Private Sub CreateReport(strSelect As String, strConn As String)

 

  ' fill a DataSet object

  Dim da As OleDbDataAdapter

  da = new OleDbDataAdapter(strSelect, strConn)

  Dim ds As DataSet = new DataSet()

  da.Fill(ds)

 

  ' get the DataTable object

  Dim dt As DataTable = ds.Tables(0)

 

  ' load report

  c1r.Load("RepDef.xml", "My Report")

 

  ' render report

  c1r.DataSource.Recordset = ds.Tables(0)

  c1ppv.Document = c1r.Document

 

End Sub

      C#

private void CreateReport(string  strSelect, string  strConn)

{

 

  // fill a DataSet object

   OleDbDataAdapter da;

  da = new OleDbDataAdapter(strSelect, strConn);

  DataSet  DataSet ds = new DataSet();

  da.Fill(ds);

 

  // get the DataTable object

   DataTable dt = ds.Tables[0];

 

  // load report

  c1r.Load("RepDef.xml", "My Report");

 

  // render report

  c1r.DataSource.Recordset = ds.Tables[0];

  c1ppv.Document = c1r.Document;

 

}

The code above creates a DataTable object using standard ADO.NET calls, and then assigns the table to the Recordset property. Note that you could also create and populate the DataTable object on the fly, without relying on and actual database.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.