Linq to SQL
-
using (apReportDataContext context = new apReportDataContext())
{
var appointments = (
from app in context.t_msts
join li in context.Lead_In
on app.apm_LeadID equals li.iLeadID into app_li
from li in app_li.DefaultIfEmpty()
join cs in context.custContactInfos on li.iLeadID equals cs.id into li_cs
from cs in li_cs.DefaultIfEmpty()
join apm in context.atm_appointment_type_masts on app.apm_type_id equals apm.atm_id into cs_apm
from apm in cs_apm.DefaultIfEmpty()select new { app.apm\_id, app.apm\_name, app.apm\_desc, app.apm\_start\_time, cs.CustomerName, apm.atm\_type\_name, }); grv.DataSource = appointments.Distinct(); grv.DataBind(); }
this is generating me result as expected now i need to pass paameters to this when generate report button is clicked, i have a drop down and if drop down value !=0 then i have to pass the value of it and if another text box field is filled then i have to pass that also as a parameter how can i do this?
-
using (apReportDataContext context = new apReportDataContext())
{
var appointments = (
from app in context.t_msts
join li in context.Lead_In
on app.apm_LeadID equals li.iLeadID into app_li
from li in app_li.DefaultIfEmpty()
join cs in context.custContactInfos on li.iLeadID equals cs.id into li_cs
from cs in li_cs.DefaultIfEmpty()
join apm in context.atm_appointment_type_masts on app.apm_type_id equals apm.atm_id into cs_apm
from apm in cs_apm.DefaultIfEmpty()select new { app.apm\_id, app.apm\_name, app.apm\_desc, app.apm\_start\_time, cs.CustomerName, apm.atm\_type\_name, }); grv.DataSource = appointments.Distinct(); grv.DataBind(); }
this is generating me result as expected now i need to pass paameters to this when generate report button is clicked, i have a drop down and if drop down value !=0 then i have to pass the value of it and if another text box field is filled then i have to pass that also as a parameter how can i do this?
-
You need to use where keyword here. It behaves same as the where clause in the SQL statements. Something like this:
from element in someIEnumerable
where element.property == someValue
select elementthanks for your reply yes what you said is working but if suppose user not entering value of text box then the value will be empty, this will give error, i need to check as this for 5 input controls, and if a control value is not empty then i have to pass that one as a parameter. how to do this.
-
thanks for your reply yes what you said is working but if suppose user not entering value of text box then the value will be empty, this will give error, i need to check as this for 5 input controls, and if a control value is not empty then i have to pass that one as a parameter. how to do this.
-
If those values are mandatory, use RequiredFieldValidator. If not, then you will have to check for the null values. Since I do not know the exact scenario in your application, cannot provide any better solution.
Thanks again for your reply .. finally i got a solution and i have done it as below.
using (apReportDataContext context = new apReportDataContext())
{
var appointments = (
from app in context.t_msts
join li in context.Lead_In on app.apm_LeadID equals li.iLeadID into app_li
from li in app_li.DefaultIfEmpty()
join cs in context.custContactInfos on li.iLeadID equals cs.id into li_cs
from cs in li_cs.DefaultIfEmpty()
join apm in context.atm_appointment_type_masts on app.apm_type_id equals apm.atm_id into cs_apm
from apm in cs_apm.DefaultIfEmpty()
select new
{
app.apm_id,
app.apm_name,
app.apm_desc,
app.apm_start_time,
cs.CustomerName,
apm.atm_type_name
}
);**
if (dropdown.SelectedIndex != 0) appointments=
apps.Where(ap => ap.apm_ID.Equals(dropdown.SelectedValue));**grv.DataSource = appointments.Distinct(); grv.DataBind();