我有个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
执行后,结果不对啊!
哪地方错了?
我有个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
执行后,结果不对啊!
哪地方错了?
你这段代码只是累加了RST返回的第一条记录的"J1"字段值Rst.RecordCount次,你那个For循环相当于a=Rst.Fields("j1").Value * Rst.RecordCount,你在For循环中加上一条语句就行了:
[此贴子已经被作者于2007-7-24 22:41:22编辑过]
“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