我有个DB1.MDB数据表,想统计某字段的合计数.
Private Sub HEJI1_Click()
Dim i, j, b As Single
Dim a
If Not Rst.EOF() Then
For i = 1 To Rst.RecordCount
a = a + Val(Rst.Fields("j1").Value)
Next i
Text1.Text = Val(a)
End If
End Sub
执行后,结果不对啊!
哪地方错了?
“Dim oCnn As Object
Set oCnn = CreateObject("ADODB.connection")
oCnn.connectionstring = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=sa;Initial Catalog=zw" ';Data Source="这个字符串根据你自己的改
oCnn.ConnectionTimeout = 30
oCnn.Open
”
这个在FORM_Load()里已经不是有了么?
如下:
Private Sub Form_Load()
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db1.mdb;Jet OleDb"
Set Conn = CreateObject("ADODB.Connection")
With Conn
.ConnectionString = ConString
.Open
End With
Rst.CursorLocation = adUseClient
Rst.Open "Select * From FL1", Conn, adOpenKeyset, adLockPessimistic, adCmdText
End Sub