How to Display Multiple DataTables Data in one CrystalReport

Jan 5 2015 5:04 AM
I have 2 DataTables one is Created From Data Entered In TextBoxes and Another DataTable Is Created From Database Sql Server. Now I Have to Show Both The DataTables Data In Single Crystal Report.
I Had Written Below Code,But It Is Showing Empty Crystal Report :
private void btnViewCrystal_Click(object sender, EventArgs e)
{
EmployeeDataSet ds = new EmployeeDataSet();
// Create First DataTable
DataTable t = ds.Tables.Add("EmpDetails");
t.Columns.Add("EmpNo", Type.GetType("System.Int32"));
t.Columns.Add("EmpName", Type.GetType("System.String"));
t.Columns.Add("DateOfBirth", Type.GetType("System.String"));
t.Columns.Add("Address", Type.GetType("System.String"));
t.Columns.Add("Country", Type.GetType("System.String"));
DataRow r;
r = t.NewRow();
r["EmpNo"] = txtEmpNo.Text;
r["EmpName "] = txtName.Text;
r["DateOfBirth"] = txtDay.Text + " /" + txtMonth.Text + " /" + txtYear.Text;
r["Address"] = txtAddress.Text;
r["Country"] = txtCountry.Text;
t.Rows.Add(r);
// Create Second DataTable
OleDbConnection cn = new OleDbConnection(ConfigurationManager.ConnectionStrings["Name_Correction.Properties.Settings.NameCorrectionConnectionString"].ConnectionString);
cn.Open();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter da = new OleDbDataAdapter();
DataTable dt = new DataTable();
cmd.Connection = cn;
cmd.CommandText = "select * from tblDepartment Where DeptNo=@DeptNo";
cmd.Parameters.Add("DeptNo", OleDbType.Integer).Value = int.Parse(txtDeptNo.Text);
da.SelectCommand = cmd;
dt.Clear();
da.Fill(dt);
ds.Tables.Add(dt);
//To Show The CrystalReport1 In CrystalReportViewer
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
}

Answers (1)