How to Display Multiple DataTables Data in Single Crystal Report In C# Windows Application

Posted by Kasani007 under C# on 12/26/2014 | Points: 10 | Views : 2663 | Status : [Member] | Replies : 0
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 : (Please help me)

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();


}




Responses

(No response found.)

Login to post response