Hi all,
I'm doing a batch update for our products database, and as far as I concern, I would never know how many and which particular fields will be edited and updated. All I did is set on/off button for those fields and user will select which field(s) to edit and hit Update button when finished. The form will then sent to Update.asp page to process and the UPDATE function will have to be smart enough to update the field(s) that was active and leave other inactive field(s) alone (because I experienced blank/NULL data when update everything included those inactive fields.)
Because of not knowing how many fields and which fields will be active, this is what I come up:
I used the "1=1" as a dummy account so that, for sure, any next field will includes ", " and so on.
Here is a test result of the sql
UPDATE tblProducts SET 1=1, ProdTypeID = '6,5,7,8' WHERE ProductID = 17
it seems innocent enough; however, data is not updated at all. I tested and know for sure the "1=1" is the problem.
Is there a way for me to work this out? I meant I still need some kind of a dummy account, but it should work for this situation. Of course, any other ADO suggestion that by-pass this technique is also welcome.
Thank you all.
I'm doing a batch update for our products database, and as far as I concern, I would never know how many and which particular fields will be edited and updated. All I did is set on/off button for those fields and user will select which field(s) to edit and hit Update button when finished. The form will then sent to Update.asp page to process and the UPDATE function will have to be smart enough to update the field(s) that was active and leave other inactive field(s) alone (because I experienced blank/NULL data when update everything included those inactive fields.)
Because of not knowing how many fields and which fields will be active, this is what I come up:
Code:
strSQL = "UPDATE tblProducts SET 1=1"
if len(sName)>0 then
strSQL = strSQL & ", ShortName = '" & sName & "' "
end if
if len(lName)>0 then
strSQL = strSQL & ", LongName = '" & lName & "' "
end if
if len(ptypeID)>0 then
strSQL = strSQL & ", ProdTypeID = '" & ptypeID & "' "
end if
if len(pmanuID)>0 then
strSQL = strSQL & ", ManuID = " & pmanuID & " "
end if
strSQL = strSQL & " WHERE ProductID = " & strID
I used the "1=1" as a dummy account so that, for sure, any next field will includes ", " and so on.
Here is a test result of the sql
UPDATE tblProducts SET 1=1, ProdTypeID = '6,5,7,8' WHERE ProductID = 17
it seems innocent enough; however, data is not updated at all. I tested and know for sure the "1=1" is the problem.
Is there a way for me to work this out? I meant I still need some kind of a dummy account, but it should work for this situation. Of course, any other ADO suggestion that by-pass this technique is also welcome.
Thank you all.