I want to create a search page having 4 dropdown lists control. These parameter must be optional. i.e. result displayed should be according to the number of parameter selected outof 4.
stored procedure is working fine
@deptName nvarchar(100) = null,
@desiName nvarchar(100) = null
as
begin
select ID,SystemType as [Product],ZoneName as Zone,DeptName as [Department],DesiName as [Designation],
IssuedTo as [Issued To],ModelName as [Model],IssuedOn as [Issued On],ItemMake [Make],ProCompany as Company,
UpsBattery as [UPS Battery],WinVersion as [Win Version],SysLicense as [System License],SerialKey as [Serial Key],
NumberStatus as [Status],SysDescription as [Description] from tblSystemRegistration
where SystemType=@productType and (ZoneName=@zoneName or @zoneName is null) and (DeptName=@deptName or @deptName is null)
and (DesiName=@desiName or @desiName is null)
end
business logic
public DataTable GetSystemReport(string styp, string zon, string dept, string desi)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = CS;
SqlDataAdapter adp = new SqlDataAdapter("spGetSystemInventory", con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
adp.SelectCommand.Parameters.AddWithValue("@productType",styp);
adp.SelectCommand.Parameters.AddWithValue("@zoneName", zon);
adp.SelectCommand.Parameters.AddWithValue("@deptName", dept);
adp.SelectCommand.Parameters.AddWithValue("@desiName", desi);
DataTable dtp = new DataTable();
adp.Fill(dtp);
return dtp;
}
.aspx.cs page
protected void btnSearchInfo_Click(object sender, EventArgs e)
{
strtype = ddlProductSubtype.SelectedItem.ToString() != null ? ddlProductSubtype.SelectedItem.ToString() : "";
strZon = ddlZone.SelectedItem.ToString() != null ? ddlZone.SelectedItem.ToString() : "";
strDept = ddlDept.SelectedItem.ToString() != null ? ddlDept.SelectedItem.ToString() : "";
strDesi = ddlDesi.SelectedItem.ToString() != null ? ddlDesi.SelectedItem.ToString() : "";
gvSearchRecord.DataSource = GetSystemReport(strtype, strZon, strDept, strDesi);
gvSearchRecord.DataBind();
}
what is wrong in this code ?