i have this application in which report is not working, i am actually a php developer and i can understand the select * from table like query but linq query is new to me..
But even in linq query there is a join concept but i am not seeing any joins in this query so i am wondering is ther anything wrong with this query or is this normal in WPF to use query like that.
var query = from t in dc.TransectionsRemittenances
from c in t.CustomerAccounts
from b in t.Beneficiaries
from bank in b.BeneBankAccounts
where t.AgentId == int.Parse(agentId)
where t.GbBranchId == GlobalClass.GbBranchID
where t.Date == givenDate
select new { t, c, b, bank };
The Actual Code is like This.
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
string agentName = string.Empty;
try
{
DateTime givenDate = DateTime.ParseExact(tbDate.Text, "M/d/yyyy", CultureInfo.InvariantCulture);
if (cmbAgents.SelectedIndex >= 0)
{
agentId = ((DataRowView)cmbAgents.SelectedItem).Row.ItemArray[0].ToString();
agentName = ((DataRowView)cmbAgents.SelectedItem).Row.ItemArray[1].ToString();
//MessageBox.Show(agentId);
//------------------------LOAD REPORT--------------------------//
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
RMSDatabase2DataSet dataset = new RMSDatabase2DataSet();
dataset.BeginInit();
DataClassesDataContext dc = new DataClassesDataContext();
DataSet1.AgentFaxDSDataTable dt = new DataSet1.AgentFaxDSDataTable();
if (GlobalClass.GbBranchID != 12)
{
var query = from t in dc.TransectionsRemittenances
from c in t.CustomerAccounts
from b in t.Beneficiaries
where t.AgentId == int.Parse(agentId)
where t.GbBranchId == GlobalClass.GbBranchID
where t.Date == givenDate
select new { t, c, b};
foreach (var d in query)
{
dt.Rows.Add(d.t.ReceiverCurrency, d.t.ReceivedAmount, d.t.Date,
d.c.Name, d.b.Name, d.b.FName, d.b.City, d.b.Address);//, "", "", "", "");
}
}
else
{
var query = from t in dc.TransectionsRemittenances
from c in t.CustomerAccounts
from b in t.Beneficiaries
from bank in b.BeneBankAccounts
where t.AgentId == int.Parse(agentId)
where t.GbBranchId == GlobalClass.GbBranchID
where t.Date == givenDate
select new { t, c, b, bank };
foreach (var d in query)
{
if (d.t.BeneSource == null)
{
dt.Rows.Add(d.t.ReceiverCurrency, d.t.ReceivedAmount, d.t.Date,
d.c.Name, d.b.Name, d.b.FName, d.b.City, d.b.Address, "", "", "", "");
}
else
{
dt.Rows.Add(d.t.ReceiverCurrency, d.t.ReceivedAmount, d.t.Date,
d.c.Name, d.b.Name, d.b.FName, d.b.City, d.b.Address, " (Bank: " + d.bank.BankName + ",",
" AccNo-" + d.bank.BankAccountNo + "-", " BCode-" + d.bank.BranchCode, ", " + d.bank.Address + ")");
}
}
//query.ToArray().
}
reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file
reportDataSource1.Value = dt;
this._reportViewer.LocalReport.DataSources.Clear();
this._reportViewer.LocalReport.DataSources.Add(reportDataSource1);
this._reportViewer.LocalReport.ReportEmbeddedResource = "RMS.rptRemittances.rdlc";
ReportParameter[] param = new ReportParameter[2];
param[0] = new ReportParameter("para_agent", agentName.ToString());
param[1] = new ReportParameter("para_forDate", givenDate.ToString("d/M/yyyy"));
this._reportViewer.LocalReport.SetParameters(param);
_reportViewer.RefreshReport();
}
}
catch (Exception ex)
{
string messageBoxText = "Enter Date Formate is incorrect, it must be 'MM/DD/YYYY'.\n\n" + ex.Message;
string caption = "Error";
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxImage icon = MessageBoxImage.Error;
MessageBox.Show(messageBoxText, caption, button, icon);
}
}
can anyone tell if query is ok and if its ok. then how its working i mean joins, inner join or left join etc. Plus what is the name of this query if its not linq query what should i look for on internet..
As i am getting no problem from this query in application developed by previous developer of my company. But i am also not getting any data thats why i am trying to check this query is ok and want to run it in MSSQL to see if there is any result generating from it.. BUt nt sure wht to do with the joins??
Aucun commentaire:
Enregistrer un commentaire