怎么使用SUM 怎么得到它的值 请帮我改一下 谢谢

wangtianyang 2006-12-03 12:57:52
Private Sub Command3_Click()
On Error GoTo gpError
Dim objCn As New Connection, objRs As New Recordset
Dim strCn As String, strSQL As String
Dim a As Integer
'建立数据库连接 ado是数据源名
strCn = "Provider=MSDASQL.1;Persist Security Info=False;" & "Data Source=ado"
objCn.ConnectionString = strCn
objCn.ConnectionTimeout = 30
objCn.Open


strSQL = "select sum(no) as total from 例子"
Set objRs.ActiveConnection = objCn
objRs.Open (strSQL)
Text4.Text = objRs("total")

objCn.Close
Set objRs = Nothing
Set objCn = Nothing

gpError:

End Sub
...全文
175 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
饮水需思源 2006-12-03
  • 打赏
  • 举报
回复
strSQL = "select sum([no]) as ftotal from 例子"
if objrs.state=adstateopen then objrs.close
objrs.open strsql,objcn,adopenkeyset,adlockreadonly
if objrs.recordcount>0 then
Text4.Text = objRs!ftotal
else
text4.text=""
end if
wangtianyang 2006-12-03
  • 打赏
  • 举报
回复
可以了 strSQL = "select sum([no]) as total from 例子"
他说的对 zq972(*^_^*)
wangtianyang 2006-12-03
  • 打赏
  • 举报
回复
我一点按钮 TEXT就显示0 根本不是和 我数据库里是有东西 不是空的
gaiwa 2006-12-03
  • 打赏
  • 举报
回复
楼主的代码会报错吗?
看错误内容就应该知道是怎么回事。

gpError:
'加一句
MsgBox Err.Description
Dunzip 2006-12-03
  • 打赏
  • 举报
回复
楼主代码好像没有问题,如果有问题可能是no引起。同意楼上的[no]
zq972 2006-12-03
  • 打赏
  • 举报
回复
strSQL = "select sum([no]) as total from 例子"
wangtianyang 2006-12-03
  • 打赏
  • 举报
回复
目的就是点击command3 text4就显示出库中列no的和
我用的是VB+access

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧