asp.net - ObjectDataSource and null parameters -
I used Visual Databet (.xsd) to develop an invoice application using Visual Web Developer 2008 EE I'm having trouble creating a custom search query. I have an ObjectDataSource which expects 4 control parameters like:
& asp: ObjectDataSource id = "odsInvoices" runat = "Server" SelectMethod = "getInvoices" typename = "blowwoice" & gt; & Lt; SelectParameters & gt; & Lt; Asp: ControlParameter ControlID = "drpProjectsFilter" type = "int32" name = "intProject" property name = "selected value" ConvertEmptyStringToNull = "True" /> & Lt; Asp: ControlParameter ControlID = "drpMonthsFilter" type = "int32" name = "intMonth" property name = "selected value" ConvertEmptyStringToNull = "True" /> & Lt; Asp: ControlParameter ControlID = "drpYearFilter" type = "int32" name = "intyear" property name = "selected value" convertActistStringTown = "true" /> & Lt; Asp: ControlParameter ControlID = "drpStatusFilter" type = "int32" name = "intestatus" property name = "selected value" convertActiststratingTotal = "true" /> & Lt; / SelectParameters & gt;
For each of these controls (dropdown) I have a default value (= empty string) and I have added the ConvertEmptyStringToNull = "True" option for each parameter. The query behind ObjectDataSource is:
SELECT ... FROM ... WHERE (YEAR (invoice in voice_date) = COALESCE (@ year, year (invoice.voice_date)) And (Invoice.Fk_project_id = COALESCE (@projectID, Invoice.fk_project_id)) and (Month (Invoice Invo_Date) = COALESCE (@ month, month (invoice.voices_date)) and (Invoice.Invoice_STAT = COALESCE (STATUS ID, COOSESE By using, I am basically saying that if they are zero and return all the rows, then out of 4 parameters Ignoring C also. The problem is that this query does not return any rows, unless I specify a value for each of the 4 values, basically this custom search
Why this is not working but any thoughts? Thanks in advance! From MSSQL documentation:
ISNULL and COALESCE equivalents, however, / P>
Then try to change your query to:
select from ... where year (invoices.invoice_date) = Isnull (@in year, year (invoices.invoice_date)) and invoice. Fk_project_id = isnull (@projectID, Invoices.fk_project_id) and month (invoices.invoice_date) = isnull (@ month, month (invoices.invoice_date)) and invoice.ivoice_status = isnull (@statusID, invoices.invoice_status)
< / Pre> Use SQL profiler to see if it is not working, your SELECT
is being implemented.
Comments
Post a Comment