发表于:2007-09-13 08:37:00
楼主
为什么我这段脚本代码执行后,在数据库中取出来的信息,在Listview中没有 列头 呢也就是列名
Listview在使用时有什么要注意的吗? 请指点 ,红色部分的代码,谁能给我翻译一下.
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim conn
Dim oRs
Dim oCom
Dim oItem
Dim m,s,n
Dim Control
sPro="provider=MSDASQL;"
sDsn="DSN=CC_wincc_sq_07_09_06_10_08_26R;"
sSer="UID= PWD= "
sCon=sPro+sDsn+sSer
sSql="select * from AMT"
MsgBox"Open with:"&vbCr &sCon &vbCr &sSql &vbCr
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=sCon
conn.CursorLocation=3
conn.Open
Set oRs=CreateObject("ADODB.Recordset")
Set oCom=CreateObject("ADODB.Command")
oCom.commandType=1
Set oCom.ActiveConnection=conn
oCom.CommandText=sSql
Set oRs=oCom.Execute
[color=#FF0000] m=oRs.Fields.Count
Set Control=ScreenItems("ListView1")
Control.ColumnHeaders.Clear
Control.ColumnHeaders.add, ,CStr(oRs.Fields(1).Name),140
Control.ColumnHeaders.add, ,CStr(oRs.Fields(2).Name),70
Control.ColumnHeaders.add, ,CStr(oRs.Fields(3).Name),70
If(m>0) Then
oRs.MoveFirst
n=0
Do While Not oRs.EOF
n=n+1
s=Left(CStr(oRs.Fields(1).Value),23)
Set oItem=Control.ListItems.Add()
oItem.text=Left(CStr(oRs.Fields(1).Value),23)
oItem.SubItems(1)=FormatNumber(oRs.Fields(2).Value,4)
oItem.SubItems(2)=Hex(ors.Fields(3).Value)
If(n>1000) Then Exit Do
oRs.MoveNext[/color]
Loop
oRs.Close
Else
End If
set oRs=nothing
conn.Close
Set conn=Nothing