麻烦大家帮我看看下面访问SQL server 的代码,问题是怎么只读取数据库的前19行?
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim oRS
Dim conn
Dim oCom
Dim oItem
Dim n
Dim oList
Dim lngValue
Dim test
Dim test03
Set test= ScreenItems("Text03")
Set test03= ScreenItems("Text04")
sPro = "Provider=SQLOLEDB;"
sDsn="Initial Catalog=shuju;"
sSer="Data Source=E6530D;uid=as;pwd=as123456;"
sCon= sPro+sDsn+sSer
oItem = test.OutputValue
sSql="SELECT PRO_ID FROM tblProduct where PRO_Name ="&oItem
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=sCon
'conn.CursorLocation=3
conn.Open
Set oRs=CreateObject("ADODB.Recordset")
Set oCom=CreateObject("ADODB.Command")
With oCom
.ActiveConnection=conn
.CommandText=sSql
End With
Set oRs=oCom.Execute
n=oRs.Fields.Count
Set oList=ScreenItems("numb02")
lngValue=""
If(n>0) Then
oRs.MoveFirst
lngValue = oRs.Fields(0).Value
'oList.OutputValue = Int(lngValue)
HMIRuntime.Tags("test_2").Write Int(lngValue)
MsgBox("查询成功")
Else
HMIRuntime.Trace("Selection returned no fields" & vbNewLine)
End If
oRs.Close
Set oRs=Nothing
conn.Close
Set conn=Nothing