Skip to main content Skip to footer

Binding ActiveReport's Section Report to an Oracle Database

Oracle happens to be a widely used datasource and let’s see how we can bind Section Reports to this database. So before we get started let’s get the ingredients in place that we would need for connecting to an Oracle datasource. The only thing that we would need is an Oracle Data Provider for .NET which would allow us to take advantage of Oracle database functionality and expose us the API that we would need to work with Oracle inside a .NET application. We have used the one that is provided by Oracle i.e. the ODP.NET library (Oracle.DataAccess.Client assembly). This library can be downloaded from here. Now that we have the ingredients in place, let’s go ahead and create an application that uses Oracle as a datasource for the a Section Report.

  1. Create a new application in Visual Studio and add ActiveReports 7 Section Reports ( code-based) File to it.
  2. Add a reference to the Oracle.DataAccess.dll in the project.
  3. Add the namespace Oracle.DataAccess.Client in the code-behind of the report in order to access the classes, methods and properties available in this assembly.
  4. Inside the ReportStart event of the report add the code for the following implementations:
    • Set the Data Source connection string
    • Set the Data Source SQL query
    • Open the connection and retrieve the data with Data Adapter and fill to the Data Table
    • Set the report’s Data Source property to this Data Table
    • Close the connection The code to achieve this is provided below: ~~~

private OracleConnection con;
private OracleCommand cmd;
private OracleDataAdapter adap;
DataTable dt = new DataTable();

private void rptOracle_ReportStart(object sender, EventArgs e)
{
string oraDB = "Data Source=XE;User;Password=hr;";
con = new OracleConnection(oraDB);
con.Open();
cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "select * from DEPARTMENTS";
cmd.CommandType = CommandType.Text;
adap = new OracleDataAdapter(cmd);
adap.Fill(dt);
this.DataSource = dt;
con.Close();
}

~~~

  1. Now, add the controls to the report to contain data and set their Data Field property to the name of the fields in the Table.
  2. Now just preview in the report designer or view the report using a viewer to see the results.

MESCIUS inc.

comments powered by Disqus