|
主要分四个步骤:
简单说一下:
第一步:建立与数据库的连接
****主要参数connection_string:数据源
方法:
Function db_connect (byRef curSession,connection_string)
dim connection
on error Resume next
'打开连接
set connection = CreateObject("ADODB.Connection")
'判断打开连接是否有错误
If Err.Number <> 0 then
db_connect= "Error # " & CStr(Err.Number) & " " & Err.Description
err.clear
Exit Function
End If
connection.Open connection_string
'判断打开数据源是否有错误
If Err.Number <> 0 then
db_connect= "Error # " & CStr(Err.Number) & " " & Err.Description
err.clear
Exit Function
End If
set curSession=connection
db_connect=0
End Function
第二步:从数据库中取数据:
*******主要参数:sql:sql查询语句;array_data:存放查询返回值
Public Function db_execute_query (byRef curSession , sql, array_data )
Dim rows
Dim col
Dim x,y
x=0
y=0
col=0
rows = 0
set rs = curSession.Execute(sql)
If Not rs.Bof And Not rs.Eof Then
rs.MoveFirst
Do Until rs.EOF
rows = rows+1
rs.MoveNext
Loop
col = rs.fields.count-1
ReDim array_data(rows-1,col)
rs.MoveFirst
Do Until rs.EOF
y=0
For I=0 To col
array_data(x,y)=rs.fields(y).Value
If IsNull(array_data(x,y)) Then
array_data(x,y)=" "
End if
y=y+1
Next
x=x+1
rs.MoveNext
Loop
End If
End Function
第三步:从页面取值:
主要用 WebTable.GetCellData(row,col)方法
第四步:
对数据库返回值和页面取到的值进行比较 |
|