0
votes

I have an Access database file in my server and I need to connect it to Crystal Reports in my C# program.

I have succeeded in connecting to the database in my program but I don't know how to connect to Crystal Report.

1

1 Answers

2
votes

Follow the following Code Snippet which will help you to connect to the Crystal Report from C# coding.

    CrystalReport1 myReport;    

    string connectionString = @"<Give your Connection String To Connect Access Database>(Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\4.accdb)";  
    string selectSQL = "<Provide the Query here to Retrieve Data>(Select ProductID,ProductName,ProductSpec From Products)";  

    OleDbConnection connection = new OleDbConnection(connectionString);  
    OleDbDataAdapter da = new OleDbDataAdapter(selectSQL, connection);  

    DataSet ds = new DataSet();  
    da.Fill(ds, "Test");  

    myReport = new CrystalReport1();  
    myReport.SetDataSource(ds);  
    myReportViewer1.ReportSource = myReport;  

    ds.Dispose();  
    connection.Close();