Is it possible to use a data table in Bold Reports®?

Yes. You can use a data table in Bold Reports® by adding it as a data source with BoldReports.Web.ReportDataSource. Follow these steps to add a sample data source with a data table.

  • Create a SQL connection and add the data source to the report in the OnReportLoaded function.

     public void OnReportLoaded(ReportViewerOptions reportOption)
          {
             System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(@"Data Source=<instancename>;Initial Catalog=<database>;User id=<username>;Password=<password>;");
             using (connection)
             {
               reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource()
               {
                 ...
               });
             }
          }
  • While adding the data source, the dataset name used in the report must be provided along with the data table, as in the following code sample.

    public void OnReportLoaded(ReportViewerOptions reportOption)
    {
      System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(@"Data Source=<instancename>;Initial Catalog=<database>;User id=<username>;Password=<password>;");
      using (connection)
      {
        reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource()
        {
          Name = "DataSet1",
          Value = this.GetDataTable(connection)
        });
      }
    }
    
    public System.Data.DataTable GetDataTable(System.Data.SqlClient.SqlConnection connection)
    {
      System.Data.DataSet dataset = new System.Data.DataSet();
    
      System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter();
    
      adapter.SelectCommand = new System.Data.SqlClient.SqlCommand(
           @"SELECT top 10 [HumanResources].[Department].[DepartmentID],[HumanResources].[Department].[Name], [HumanResources].[Department].[GroupName],[HumanResources].[Department].[ModifiedDate] FROM[HumanResources].[Department]",
           connection);
      adapter.Fill(dataset);
      return dataset.Tables[0];
    }

Here the Name is case-sensitive and it should be same as in the dataset name in the report definition. The Value also accepts IList and DataSet inputs.