المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to add data from multiple table to datagrid in C#



C# Programming
04-10-2009, 08:43 AM
Hi i am building an application in which i want to generate a report. That report consists of data from multiple tables. I tried doing this but when the datagrid is populated with the dataset/datatable the record from second table comes on second row & from third table comes on third row. I am using access database. can someone help me out of this.
Thanks in advance. the code is as shown below.

private void Form1_Load(object sender, EventArgs e)
{

try
{

con = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=e:/ReportTest/ReportTest/ContractSystemDB.mdb");
con.Open();

ds = new DataSet();
dt = new DataTable("ashish");

cmd = new OleDbCommand("select * from CommonData",con);
rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
da = new OleDbDataAdapter("select * from InitialApproval where InitialApproval.PrNo='"+rd.GetString(0)+"'",con);
da.Fill(ds);
da.Dispose();

da1 = new OleDbDataAdapter("select EstimatedVal,FwdDtByPSD from PSDApproval where PSDApproval.PrNo='" + rd.GetString(0) + "'",con);
da1.Fill(ds);
da1.Dispose();

da2 = new OleDbDataAdapter("select POValue,rcd_dtCC,saving from CommonData where CommonData.PrNo='" + rd.GetString(0) + "'", con);
da2.Fill(ds);
da2.Dispose();
}
}
contractSystemDBDataSetBindingSource.DataSource = ds;
MyGrid.DataSource = contractSystemDBDataSetBindingSource.DataSource;

MessageBox.Show("Record Added To Grid View");
}
catch (Exception ex)
{
MessageBox.Show("Error==>" + ex);
}
finally
{
con.Close();
}
}