Hi all,
I am developing windows application. In this application I need to use the crystal report. I need to add the fields by programmatically. I am using dataset to bind the table values with crystal report. But when I set the datasource value to the crystalreport i am getting error that says "The report has no table". How to solve this? Here, I attached my code.
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = databaseconnectionstring;
StringBuilder sbSql = new StringBuilder();
sbSql.Append("SELECT ");
sbSql.Append("Face_page.[Case], Face_page.Type, Face_page.Location, Face_page.Flag, ");
sbSql.Append("Face_page.Officer, Face_page.ID, Face_page.Written, Face_page.Shift, ");
sbSql.Append("Face_page.DaysOff ");
sbSql.Append("FROM ");
sbSql.Append(" Face_page ");
sbSql.Append(" where ");
sbSql.Append("Face_page.[Case] = '71-111-1111E'");
string sql = sbSql.ToString();
DataSet ds = new DataSet();
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "sample");
CrystalReport4 cryReport1 = new CrystalReport4();
if(ds.Tables.Count>0) {
cryReport1.SetDataSource(ds.Tables[0]); // ----> I am getting error here..
}
crystalReportViewer1.Visible = true;
this.crystalReportViewer1.ReportSource = cryReport1;
con.Close();
}