norbi771
Posts: 3
|
Posted: 07/16/2010, 5:42 AM |
|
Hi,
I usually use CCS for PHP programming, but today I need to modify ASP app written with CCS.
How can I use omit if empty feature in ASP?
I have a record form with some fields on it which are specified in custom update method.
In particular situation I would like to exclude some of these fields from update operation, how can I achieve that?
I thought I could set the particular field to NULL (Empty in ASP I guess) in BEFORE UPDATE event, but it doesn't seem to work.
I dug into the source code generated by css:
Dim IsDef_Invest_Year : IsDef_Invest_Year = CCIsDefined("Invest_Year" , "Control")
Dim IsDef_Invest_Month : IsDef_Invest_Month = CCIsDefined("Invest_Month" , "Control")
If Not UpdateOmitIfEmpty("SiteID") Or IsDef_SiteID Then Cmd.AddSQLStrings "[SiteID]=" & Connection.ToSQL(Cmd.Parameters.getParamByID(1), Cmd.Parameters.getParamByID(1).DataType), Empty
If Not UpdateOmitIfEmpty("Invest_Year") Or IsDef_Invest_Year Then Cmd.AddSQLStrings "[Invest_Year]=" & Connection.ToSQL(Cmd.Parameters.getParamByID(2), Cmd.Parameters.getParamByID(2).DataType), Empty
and
'CCIsDefined @0-519FFE4F
Function CCIsDefined(ParameterName, Scope)
Select Case Scope
Case "URL"
CCIsDefined = Not IsEmpty(Request.QueryString(ParameterName))
Case "Form","Control"
If IsMutipartEncoding Then
CCIsDefined = Not IsEmpty(objUpload.Form(ParameterName))
Else
CCIsDefined = Not IsEmpty(Request.Form(ParameterName))
End If
...
... and it seems to me that if I have some data submitted by the form (in POST) then I cannot omit that data in the query ... but since I use ASP very rarely I might be wrong and I hope I am wrong.
Could you advice how to proceed? Maybe there is different approach?
Brgs
Norbert
|
lboeldt
Posts: 53
|
Posted: 07/16/2010, 12:35 PM |
|
I did a quick test of IsEmpty with a querystring. I made a page that contains the following code.
<% = isempty( request.querystring("hello") ) %>
If you visit the page with an empty querystring you'll see that isempty is true. However, if you include ?hello= as the querystring isEmpty returns false. It seems if the querystring or form item exists in the get/post request it is considered blank "" and not empty.
With this insight in mind the following code should get your function to return the desired result.
function UpdateOmitIfEmpty(param_name)
if request.form(param_name)&"" = "" then
' it's blank/no value
UpdateOmitIfEmpty = true
else
' it has a value assigned
UpdateOmitIfEmpty = false
end if
end function
|