If you want to filter a DataSet using multiple parameters that is nothing but multiple search
Suppose if you have Dataset like this
DataSet ds_comm = new DataSet();
SqlDataAdapter da_comm = new SqlDataAdapter("select b.PId,b.ClientName, b.FromDate as Date,b.Payroll as GrossPayroll,c.Amount as CommissionDue,c.PEO,c.Month,c.Year from TBL_COMMISSION_SETUP b JOIN TBL_PAYEE_DETAILS C ON b.PId=c.PId and b.FromDate=c.FromDate group by b.PId, b.FromDate,b.ClientName,b.Payroll,c.Amount,c.PEO,c.Month,c.Year order by b.ClientName asc ", con);
da_comm.Fill(ds_comm);
you want to filter this DataSet using parameters like Payee,Month,Year,
you can use this method to do that task..you can add as many as parameters like this to filter the Dataset
ds_comm = SearchMonthYear(ds_comm);
public DataSet Search_SalesRep(DataSet ds)
{
DataSet ds_return = new DataSet();
ds_return.Clear();
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
DataView dv = new DataView(dt);
string filter = "";
if (filter != "")
{
if (ddlMonth.SelectedItem.ToString() != "Select")
{
filter += " and Month='" + ddlMonth.SelectedValue.ToString() + "' ";
}
}
else
{
if (ddlMonth.SelectedItem.ToString() != "Select")
{
filter += " Month='" + ddlMonth.SelectedValue.ToString() + "' ";
}
}
if (filter != "")
{
if (ddlYear.SelectedItem.ToString() != "Select")
{
filter += " and Year='" + ddlYear.SelectedValue.ToString() + "' ";
}
}
else
{
if (ddlYear.SelectedItem.ToString() != "Select")
{
filter += " Year='" + ddlYear.SelectedValue.ToString() + "' ";
}
}
if (filter != "")
{
if (ddlSalesRep.SelectedItem.ToString() != "Select")
{
filter += " and Payee='" + ddlSalesRep.SelectedItem.ToString() + "' ";
}
}
else
{
if (ddlSalesRep.SelectedItem.ToString() != "Select")
{
filter += " Payee like '" + ddlSalesRep.SelectedItem.ToString() + "' ";
}
}
filter = filter.Trim();
dv.RowFilter = filter;
if (dv.Table.Rows.Count > 0)
{
dt = dv.ToTable();
ds_return.Tables.Add(dt);
}
return ds_return;
}
else
{
return ds;
}
}
Suppose if you have Dataset like this
DataSet ds_comm = new DataSet();
SqlDataAdapter da_comm = new SqlDataAdapter("select b.PId,b.ClientName, b.FromDate as Date,b.Payroll as GrossPayroll,c.Amount as CommissionDue,c.PEO,c.Month,c.Year from TBL_COMMISSION_SETUP b JOIN TBL_PAYEE_DETAILS C ON b.PId=c.PId and b.FromDate=c.FromDate group by b.PId, b.FromDate,b.ClientName,b.Payroll,c.Amount,c.PEO,c.Month,c.Year order by b.ClientName asc ", con);
da_comm.Fill(ds_comm);
you want to filter this DataSet using parameters like Payee,Month,Year,
you can use this method to do that task..you can add as many as parameters like this to filter the Dataset
ds_comm = SearchMonthYear(ds_comm);
public DataSet Search_SalesRep(DataSet ds)
{
DataSet ds_return = new DataSet();
ds_return.Clear();
if (ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
DataView dv = new DataView(dt);
string filter = "";
if (filter != "")
{
if (ddlMonth.SelectedItem.ToString() != "Select")
{
filter += " and Month='" + ddlMonth.SelectedValue.ToString() + "' ";
}
}
else
{
if (ddlMonth.SelectedItem.ToString() != "Select")
{
filter += " Month='" + ddlMonth.SelectedValue.ToString() + "' ";
}
}
if (filter != "")
{
if (ddlYear.SelectedItem.ToString() != "Select")
{
filter += " and Year='" + ddlYear.SelectedValue.ToString() + "' ";
}
}
else
{
if (ddlYear.SelectedItem.ToString() != "Select")
{
filter += " Year='" + ddlYear.SelectedValue.ToString() + "' ";
}
}
if (filter != "")
{
if (ddlSalesRep.SelectedItem.ToString() != "Select")
{
filter += " and Payee='" + ddlSalesRep.SelectedItem.ToString() + "' ";
}
}
else
{
if (ddlSalesRep.SelectedItem.ToString() != "Select")
{
filter += " Payee like '" + ddlSalesRep.SelectedItem.ToString() + "' ";
}
}
filter = filter.Trim();
dv.RowFilter = filter;
if (dv.Table.Rows.Count > 0)
{
dt = dv.ToTable();
ds_return.Tables.Add(dt);
}
return ds_return;
}
else
{
return ds;
}
}
No comments:
Post a Comment