标题:我有个DB1.MDB数据表,想统计某字段的合计数
取消只看楼主
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
结帖率:84.62%
 问题点数:0 回复次数:5 
我有个DB1.MDB数据表,想统计某字段的合计数

我有个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

执行后,结果不对啊!

哪地方错了?

搜索更多相关主题的帖子: 合计数 字段 数据 统计 
2007-07-23 21:38
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
谢谢!

用SQL语句又怎么写呢?
2007-07-24 13:54
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

用SQL语句,这样写,行么?

Private Sub HEJI1_Click()

If Not Rst.EOF() Then
select SUM as total from FL1

Text1.Text = rst.field(sun).value
End If
End Sub

在我的DB1里面的表FL1里还有个字段:SUM

2007-07-24 17:54
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

我在表FL1的设计视图添加了:“heji”的字段,

我改用SQL语句如下:

Private Sub HEJI1_Click()

If Not Rst.EOF() Then
select sum(heji) as total from FL1

Text1.Text = rst.field(heji).value
End If
End Sub

执行时出现:

缺少CASE???

到底sum是函数表达式,还是total函数表达式呢?

2007-07-24 22:35
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 

“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

2007-07-24 23:09
lijun337
Rank: 1
等 级:新手上路
帖 子:379
专家分:5
注 册:2006-4-12
得分:0 
那么,可不可以在VB里面添加SQL语句呢?

“Rst.Open "Select * From FL1", Conn, adOpenKeyset, adLockPessimistic, adCmdText

这算不算引用了SQL语句呢?

我那句该如何写呢?
2007-07-25 21:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-157573-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055162 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved