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:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
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 End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
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; } |
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.