|
本帖最后由 betty7zhang 于 2012-8-14 14:48 编辑
Dim Cnn
Dim Rst
Dim strCnn
Set Cnn = CreateObject("ADODB.Connection")
Set Rst =CreateObject("ADODB.Recordset")
strCnn="rovider=SQLOLEDB.1assword=XXXersist Security Info=True;User ID=XXX;Initial Catalog=DB_Name;Data Source=DB_IPAddress;"
Cnn.Open strCnn
If Cnn.State=0 Then
Reporter.ReportEvent micFail,"testing","数据库连接失败"
else
Reporter.ReportEvent micPass, "testing","数据库连接成功"
End If
If Cnn.State<>0 Then
strsql="select * from tb_General_Info"
Rst.Open strsql,Cnn
i=1
Do While Not Rst.eof
DataTable.GlobalSheet.SetCurrentRow(i)
DataTable("MerchantID","Global")=Rst("MerchantID").value
DataTable("StoreID","Global")=Rst("StoreID").value
DataTable("CustomerID","Global")=Rst("CustomerID").value
DataTable("CustomerClientIP","Global")=Rst("CustomerClientIP").value
DataTable("RequestorMachineName","Global")=Rst("RequestorMachineName").value
DataTable("ReturnURL","Global")=Rst("ReturnURL").value
DataTable("CustomField","Global")=Rst("CustomField").value
DataTable("OrderID","Global")=Rst("OrderID").value
DataTable("Operation","Global")=Rst("Operation").value
DataTable("IsManualTransaction","Global")=Rst("IsManualTransaction").value
Rst.MoveNext
i=i+1
Loop
Rst.Close
Cnn.Close
Set Rst=nothing
Set cnn=nothing
End If
想简化一下这个脚本,用for 循环将所查到表中的多列数据写入datatable里,而不用手动的在脚本中写多条类似这样的语句
DataTable("MerchantID","Global")=Rst("MerchantID").value
大家有什么好的建议吗?求教。
还有一个问题就是如何将这段脚本写成function供其它脚本运行时调用呢? |
|