Am trying to bind data (Master Details) to XtraReport programmatic. If Master is single data/values means XtraReport working fine. But in my case Master is multiple data/values, here all Details data is prints on all Masters.
eg. (Vehicle Report) - Here 1)Cars & 2)Bikes are Master, Details of Cars Master is BMW, Datsun, Hyundai. Details of Bike Master is Honda, Moto, Yamaha. Now I want to print like this
Report
Cars
BMW
Datsun
Hyundai
Bikes
Honda
Moto
Yamaha
but it printing like this
Report
Cars
BMW
Datsun
Hyundai
Honda
Moto
Yamaha
Bikes
BMW
Datsun
Hyundai
Honda
Moto
Yamaha
Already I place Labels in designer XtraReports. This is my code to prints data on XtraReports programmatic
private void Report1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
try
{
StrConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Properties.Settings.Default.DataPath + @"CMDB\database.mdb";
string qry2 = "SELECT chequeid AS ChqBukId, chdescri AS ChqBukDesc, (SELECT bankname FROM tblBankMaster WHERE bank_id=tbchequebook.bankID) AS BankName FROM tbchequebook";
OleDbDataAdapter adapter1 = new OleDbDataAdapter(qry2, StrConnection);
DataSet ds1 = new DataSet();
adapter1.Fill(ds1, "Detail");
ds1.Tables[0].TableName = "QryBank";
DetailReport.DataSource = ds1;
XRBinding bindingBankName = new XRBinding("Text", ds1, "QryBank.BankName");
TXE_BankName.DataBindings.Add(bindingBankName);
XRBinding bindingchqbukame = new XRBinding("Text", ds1, "QryBank.ChqBukDesc");
TXE_ChequeBookDesc.DataBindings.Add(bindingchqbukame);
string qry4 = "SELECT chq_no, chq_date, party_name, chq_amount FROM tblchequeleafnew WHERE Status='P' ";
OleDbDataAdapter adapter3 = new OleDbDataAdapter(qry4, StrConnection);
DataSet ds3 = new DataSet();
adapter3.Fill(ds3, "Detail2");
ds3.Tables[0].TableName = "QryCheque";
DetailReport1.DataSource = ds3;
XRBinding bindingChqNo = new XRBinding("Text", ds3, "QryCheque.chq_no");
TXE_ChequeNo.DataBindings.Add(bindingChqNo);
XRBinding bindingChqDate = new XRBinding("Text", ds3, "QryCheque.chq_date", "{0:MM/dd/yyyy}");
TXE_ChequeDate.DataBindings.Add(bindingChqDate);
XRBinding bindingPartyName = new XRBinding("Text", ds3, "QryCheque.party_name");
TXE_PartyName.DataBindings.Add(bindingPartyName);
XRBinding bindingChqAmt = new XRBinding("Text", ds3, "QryCheque.chq_amount", "{0:N2}");
TXE_ChequeAmount.DataBindings.Add(bindingChqAmt);
}
catch (Exception ex)
{
XtraMessagebox.Show(ex.message.tostring());
}
}
This is my XtraReport
How to solve this to get exact Master & Its Details. Using this above code am getting Master exactly, but it show all details under all masters.
You need to set up relations between your master and details levels.
If you are using
DataSet
then you need to use oneDataSet
object for allDataSource
members andDataSet.Relations
collection to create the relations between your tables. Also you need to use the relation name asDetailReport.DataMember
property and use the same relation name in bindings.Here is example: