新手用vb读取SQL压缩数据库求分页显示指导
command2 点击后是查询程序如下
Private Sub Command2_Click()
On Error GoTo 0
Dim sPro, sSer, sCon, sDsn, DSNName
Dim conn1, oRs1, oCom1, sSql1, m, conn2, oRs2, oCom2, sSql2
' Dim conn1, oRs1, oCom1, sSql1, m,
Dim oList, oItem, i, j
Dim WinCC As Object
Set WinCC = CreateObject("WinCC-Runtime-Project")
Dim database
database = WinCC.GetValue("@DatasourceNameRT")
sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog= " & database & ";"
sSer = "Data Source=.\WinCC;User ID=sa;"
sCon = sPro & sDsn & sSer
Text1.Text = DateAdd("h", -8, DTPicker1)
Text2.Text = DateAdd("h", -8, DTPicker2)
' sSql = "TAG:R,('PV\F1';'PV\F2'),'" & Text1.Text & "','" & Text2.Text & "'"
sSql1 = "TAG:R,('PV\F1'),'" & Text1.Text & "','" & Text2.Text & "'"
sSql2 = "TAG:R,('PV\F2'),'" & Text1.Text & "','" & Text2.Text & "'"
Set conn1 = CreateObject("ADODB.Connection")
conn1.ConnectionString = sCon
conn1.CursorLocation = 3
conn1.Open
Set oRs1 = CreateObject("ADODB.Recordset")
Set oCom1 = CreateObject("ADODB.Command")
oCom1.CommandType = 1
Set oCom1.ActiveConnection = conn1
oCom1.CommandText = sSql1
Set oRs1 = oCom1.Execute
Set conn2 = CreateObject("ADODB.Connection")
conn2.ConnectionString = sCon
conn2.CursorLocation = 3
conn2.Open
Set oRs2 = CreateObject("ADODB.Recordset")
Set oCom2 = CreateObject("ADODB.Command")
oCom2.CommandType = 1
Set oCom2.ActiveConnection = conn2
oCom2.CommandText = sSql2
Set oRs2 = oCom2.Execute
flex2.Clear
If (Not oRs1.EOF) Then
oRs1.MoveFirst
i = 1
Do While Not oRs1.EOF
flex2.TextMatrix(i, 1) = i
flex2.TextMatrix(i, 2) = DateAdd("h", 8, oRs1.Fields(1).Value)
flex2.TextMatrix(i, 3) = CStr(oRs1.Fields(2).Value)
flex2.TextMatrix(i, 4) = CStr(oRs2.Fields(2).Value)
oRs1.MoveNext
oRs2.MoveNext
i = i + 1
Loop
oRs1.Close
oRs2.Close
End If
flex2.Rows = 100
flex2.Cols = 5
'设置列标头。
s$ = "^|^序号 |^ 时间 |^ 压力 |^ 温度 "
flex2.FormatString = s$
Set oRs1 = Nothing
Set oCom1 = Nothing
Set conn1 = Nothing
Set oRs2 = Nothing
Set oCom2 = Nothing
Set conn2 = Nothing
End Sub
========================
Private Sub Form_Activate()
flex2.Rows = 100
flex2.Cols = 5
'设置列标头。
s$ = "^|^序号 |^ 时间 |^ 压力 |^ 温度 "
flex2.FormatString = s$
End Sub
--------------------编程问答-------------------- wincc数据库不支持服务器端的分页,可以装入recordset,然后在客户端分页。
补充:VB , 数据库(包含打印,安装,报表)