null parameter in asp or ado command object

embaliasalmem

New Member
I have a form in asp with two text boxes. If user enters a value in it and submit, it displays data from MS access query for the selected dates by user. If users just leave both text boxes blanks, I want to display complete output from the database.
This is my sample query in access :\[code\]select column_date, field1, field2, sum(field3) from table1where field1 like '*xyz' and column_date between [@startdate] and [@enddate]group by column_date, field1, field2\[/code\]My asp codes are similar to below :\[code\]objCmd.CommandText = "Query"objCmd.CommandType = adCmdStoredProcSet objParam = objCmd.CreateParameter("@startdate" , adInteger, adParamInput, 0, 0)objCmd.Parameters.Append objParamSet objParam = objCmd.CreateParameter("@enddate" , adInteger, adParamInput, 0, 0)objCmd.Parameters.Append objParamif request.form ("startdate") = "" ThenobjCmd.Parameters ("@startdate") = 1ElseobjCmd.Parameters("@startdate") = request.form("startdate")objCmd.Parameters("@enddate") = request.form("enddate")End ifif request.form ("enddate") = "" ThenobjCmd.Parameters ("@enddate") = 31ElseobjCmd.Parameters("@startdate") = request.form("startdate")objCmd.Parameters("@enddate") = request.form("enddate")End if................\[/code\]Please note my startdate and enddates are text datatype with just numbers e.g. 1, 2, 3, 4, 5 ( 1 means 1st July 2012, 2 means 2nd July 2012)I have two text boxes name "startdate" and "enddate". When user enters dates in the boxes, it returns data between the two dates from the query. If user leaves blank, it shows error.But I want to make sure if user leave both text boxes blank, it returns all values from the query. If user input a single value in any of the two text boxes, it should return data only for that date. I'm not sure how can I achieve it.
 
Back
Top