Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I am working with Crystal Reports in C# using a SQL Server database, I cannot proceed with my project because I am getting an error

> Load Save Report Exception

on the line which I am going to set the data source of my Crystal report.

Any help will be appreciated.

Here is my code:

C#
SqlConnection con = new SqlConnection();
 string conString = @"data source =JR-PC\SQLEXPRESS;initial catalog = election;integrated security =true;";
 string sql = "Select can_names,can_pos,partylist,num_votes from tbl_Candidates";

 con = new SqlConnection(conString);
 con.Open();

 SqlDataAdapter da = new SqlDataAdapter(sql, con);
 ReportPracice._DATASETS.DataSet1 ds = new ReportPracice._DATASETS.DataSet1();
 da.Fill(ds, "tbl_Candidates");

 MessageBox.Show(ds.Tables[1].Rows.Count.ToString());
 con.Close();

 ReportPracice._REPORTS.CrystalReport1 rpt = new ReportPracice._REPORTS.CrystalReport1();
 rpt.SetDataSource(ds.Tables[1]); //in this line, where I am getting that error.
 crystalReportViewer1.ReportSource = rpt;
 crystalReportViewer1.Refresh();
Posted
Updated 15-Jun-13 23:32pm
v2
Comments
Manu Thalasseril 16-Jun-13 6:42am    
try with this one
ds.Tables[0]

1 solution

Have a look at this,

C#
SqlConnection con = new SqlConnection();
    string conString = @"data source =JR-PC\SQLEXPRESS;initial catalog = election;integrated security =true;";
    string sql = "Select can_names,can_pos,partylist,num_votes from tbl_Candidates";
    
    con = new SqlConnection(conString);
    con.Open();
    
    SqlDataAdapter da = new SqlDataAdapter(sql, con);
    ReportPracice._DATASETS.DataSet1 ds = new ReportPracice._DATASETS.DataSet1();
    da.Fill(ds, "tbl_Candidates");
    
    MessageBox.Show(ds.Tables["tbl_Candidates"].Rows.Count.ToString());
    con.Close();
    
    ReportPracice._REPORTS.CrystalReport1 rpt = new ReportPracice._REPORTS.CrystalReport1();
    rpt.SetDataSource(ds.Tables["tbl_Candidates"]); //Use table Name within those Square braces or try with index [0]
    crystalReportViewer1.ReportSource = rpt;
    crystalReportViewer1.Refresh();




Best Regards.
 
Share this answer
 
Comments
Member 10659826 22-Mar-14 7:27am    
I tried above code but still i get error that "Failed to load database information"
Please give solution
Thank You

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900