I'll give you a more representative program, which will probably be helpful
<%@ LANGUAGE = VBScript%>
<%
'------------------------------------------
'The simple database compiled last night (ACECESS, with id, password,
'register3 fields) operation, only single form conditional operation is supported.
'But it doesn't seem to be useful :)
'col: The field name to be queried (must be added)
'colvalue: The value of the field to be updated and added (no replacement for "")
'table: table name (must be added)
'keyid: field name of query condition (no use "" instead, optional)
'keyvalue: query the value of the condition field (without using "" instead, optional)
'col and colvalue must appear in pairs
'keyid and keyvalue must appear at the same time
'------------------------------------------
%>
<%
Function DB_execute(col,colvalue,table,keyid,keyvalue,bz)
Dim ConnStr,conn,rs,sql
ConnStr="Provider=.4.0;Data Source="&("data/")
Set conn = ("")
ConnStr
set rs=("")
for i=0 to UBound(col) step 1
if UBound(col)<>i then
sql=sql&col(i)&", "
else
sql=sql&col(i)&" "
end if
next
if keyid <> "" then
sql="select "&sql&"from "&table&" where "&keyid&"='"&keyvalue&"'"
else
sql="select "&sql&"from "&table
end if
select case bz
case "o"
sql,conn,1,1
dim rsnum
rsnum=
if rsnum > 0 then
dim rsArray()
redim rsArray(rsnum,UBound(col))
for i=0 to UBound(col) step 1
rsArray(0,i)=col(i)
next
for i=1 to rsnum step 1
for j=0 to UBound(col) step 1
rsArray(i,j)=rs(col(j))
next
next
DB_execute=rsArray
else
DB_execute="No data was found"
end if
set rs=nothing
case "u"
sql,conn,3,3
if > 0 then
for i=0 to UBound(col) step 1
rs(col(i))=colvalue(i)
next
else
DB_execute="No data was found"
end if
set rs=nothing
case "i"
sql,conn,3,3
for i=0 to UBound(col) step 1
rs(col(i))=colvalue(i)
next
DB_execute="Add data successfully"
set rs=nothing
case "d"
sql="delete from "&table&" where "&keyid&"='"&keyvalue&"'"
sql
DB_execute="Delete data successfully"
end select
set conn=nothing
end Function
%>
<%
'Return to the record set
'temp=DB_execute(Array("id","password","register"),"","users","","","o")
' temp(1,2)
'Add a record
'temp=DB_execute(Array("id","password","register"),Array("test","test","0"),"users","","","i")
' temp
'Update a record
'temp=DB_execute(Array("id","password","register"),Array("new","new","1"),"users","id","test","u")
' temp
'Delete a record
'temp=DB_execute(Array("id","password","register"),"","users","id","new1","d")
' temp
%>
Previous page12Read the full text