ActiveReports 18 .NET Edition
Developers / Working with Reports / Page/RDLX Report / Bind a Page/RDLX Report to Data / Bind Page/RDLX Report to SQL, OLEDB, and ODBC Data Providers
In This Topic
    Bind Page/RDLX Report to SQL, OLEDB, and ODBC Data Providers
    In This Topic

    Using a database as a data source is one of the most common scenarios when you work with reports. This topic explains how to bind your ActiveReports report to a SQL, OLEDB or ODBC data source.

    The example below uses a SQL database as a data source.

    Copy Code
    private PageReport LoadReport()
    {       
        string path = ""; // Your path to the report
        PageReport report = new PageReport(new FileInfo(path));
        report.Document.LocateCredentials += OnLocateCredentials;
       
        string dataProviderName = "SQL"; // Or use "OLEDB" or "ODBC" if you need it
       
        DataSource dataSource = report.Report.DataSources[0]; // Your data source
        if(dataSource.ConnectionProperties.DataProvider == dataProviderName)
        {
            dataSource.ConnectionProperties.ConnectString = ConfigurationManager.ConnectionStrings["YourConnectionString"].ConnectionString;
        }
       
        return report;
    }
    private void OnLocateCredentials(object sender, LocateCredentialsEventArgs args)
    {
        args.Password = ""; // Your password if you need it
        args.UserName = ""; // Your username if you need it
    }
    

    Use the following strings to connect to different data providers: 

    Note: When you are using an ODBC/OLEDB data provider, make sure that the required driver is installed on your computer. Otherwise, you cannot use this data provider.

    When working with a data provider, you may need to process user credentials to work with the target source. The LocateCredentials event is used for this purpose.

    Copy Code
    report.Document.LocateCredentials += OnLocateCredentials;
    

    Assign a handler that specifies the password and username when they are requested.

    Copy Code
    private void OnLocateCredentials(object sender, LocateCredentialsEventArgs args)
    {
        args.Password = ""; // Your password if you need it
        args.UserName = ""; // Your username if you need it
    }
    

    The event handler receives an argument of the LocateCredentialsEventArgs type that contains data, related to this event. The following LocateCredentialsEventArgs properties provide information, specific to this event.

    Note: We assume that the report has defined data fields and datasets, which can be done in various ways, e.g., in the Web or Windows Forms Designer.