The most irritated refers according to expressing sheet namely content when operating a database every time writes Sql sentence, especially when the field is more very troublesome, easily easy clerical error. So I wrote the makes Sql statement function below, with feel OK still.
Program code:
<%
'========All function did not join fault tolerance mechanism under, must assure the validity of parameter so========
'================Parameter explains================
What ' this Function returns is the Sql statement that inserts data
' attention: Use this Function to must make the field name in the field name in Form and database uniform
' and pushbutton cannot be Submit, want to be Button, the Submit method that adopts JavaScript submits watch sheet
'objForm must be Request.Form
'tbName is the watch name that inserts data
'numStr causes the field that come to do not need to use only quote, comma (is used between the field, ) break up, did not replace with "" please
'=======================================
Function InsertStr(objForm, tbName, numStr)Dim TbField()Dim TbfieldVal()I=0For Each ObjItem In ObjFormRedim Preserve TbField(i)TbField(i)=objItemRedim Preserve TbfieldVal(i)NumPos=instr(numStr, objItem)If NumPos<>0 ThenTbfieldVal(i)=trim(objForm(objItem) )ElseTbfieldVal(i)= "'" &trim(objForm(objItem) )&"' "End IfI=i 1NextInsertStr= "insert Into " &tbName&"(" &join(tbField, ", &") Values(" &join(tbfieldVal, ", &") "
End Function
'===================Parameter explains=========================
The updates data Sql statement that ' this Function returns
' attention: Use this Function to must make the field name in the field name in Form and database uniform
' and pushbutton cannot be Submit, want to be Button, the Submit method that adopts Javascript submits watch sheet
'objForm must be Request.Form
'tbName is the watch name that renews data
'whereField is updated conditional field, many use (please, ) break up
The setting when 'whereJoin has many for newer conditional field is And or Or
'numStr causes the field that come to do not need to use only quote, comma (is used between the field, ) break up, did not replace with "" please
'===================================================
Function UpdateStr(objForm, tbName, whereField, whereJoin, numStr)Dim SetFieldVal()Dim WhereStrArr()I=0T=0For Each ObjItem In ObjFormWherePos=instr(whereField, objItem)If WherePos=0 ThenRedim Preserve SetFieldVal(i)NumPos=instr(numStr, objItem)If NumPos<>0 ThenSetFieldVal(i)=objItem&"=" &trim(objForm(objItem) )ElseSetFieldVal(i)=objItem&"='" &trim(objForm(objItem) )&"' "End IfI=i 1ElseRedim Preserve WhereStrArr(t)NumPos2=instr(numStr, objItem)If NumPos2<>0 ThenWhereStrArr(t)=objItem&"=" &trim(objForm(objItem) )ElseWhereStrArr(t)=objItem&"='" &trim(objForm(objItem) )&"' "End IfT=t 1End IfNextWherePos2=instr(whereField, ", If WherePos2<>0 ThenWhereStr= " Where " &join(whereStrArr, "" &whereJoin&"" )ElseWhereStrArray=whereStrArrWhereStr= " Where " &whereStrArray(0)End IfUpdateStr= "update " &tbName&"Set " &join(setFieldVal, ", ") &whereStr
Previous12 Next
Hot Tags: