VB datagrid求和
两列"现金"、"刷卡"求总和到showtxt10.text为什么不行呢?rs3.Open"selectsum(现金)as现金,sum(刷卡)as刷卡fromstudwhe...
两列"现金"、"刷卡"求总和到showtxt10.text为什么不行呢?
rs3.Open "select sum(现金) as 现金 ,sum(刷卡) as 刷卡 from stud where 姓名 like '%" & showtxt1.Text & "%'", cn, 3, 3
showtxt10.Text = rs3.Fields("现金") + rs3.fields("刷卡") 展开
rs3.Open "select sum(现金) as 现金 ,sum(刷卡) as 刷卡 from stud where 姓名 like '%" & showtxt1.Text & "%'", cn, 3, 3
showtxt10.Text = rs3.Fields("现金") + rs3.fields("刷卡") 展开
2个回答
展开全部
以下这段代码是测试通过的,你对照一下:
(先要在菜单“工程”中“引用” MicroSoft ActiveX Data Object x.x Library(用最新版本))
Private Sub Command1_Click()
Dim sConnString As String
Dim rs3 As ADODB.Recordset
Dim cn As ADODB.Connection
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\cash.mdb" '换成你的数据库文件名称
Set cn = New ADODB.Connection
cn.Open sConnString
Set rs3 = New ADODB.Recordset
Rem 确认表名是stud,且有字段“姓名”、“现金”、“刷卡”等,窗体上有showtxt1和showtxt10文本框
rs3.Open "select sum(现金) as 现金 ,sum(刷卡) as 刷卡 from stud where 姓名 like '%" & showtxt1.Text & "%'", cn, 3, 3
showtxt10.Text = rs3.Fields("现金") + rs3.Fields("刷卡")
rs3.Close
End Sub
(先要在菜单“工程”中“引用” MicroSoft ActiveX Data Object x.x Library(用最新版本))
Private Sub Command1_Click()
Dim sConnString As String
Dim rs3 As ADODB.Recordset
Dim cn As ADODB.Connection
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\cash.mdb" '换成你的数据库文件名称
Set cn = New ADODB.Connection
cn.Open sConnString
Set rs3 = New ADODB.Recordset
Rem 确认表名是stud,且有字段“姓名”、“现金”、“刷卡”等,窗体上有showtxt1和showtxt10文本框
rs3.Open "select sum(现金) as 现金 ,sum(刷卡) as 刷卡 from stud where 姓名 like '%" & showtxt1.Text & "%'", cn, 3, 3
showtxt10.Text = rs3.Fields("现金") + rs3.Fields("刷卡")
rs3.Close
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询