我想把数据库中的数据显示在MSFlexGrid中,但把具有相同值的字段显示一次,而其它字段的值相加:
dim qua as double
Set rsSto = New ADODB.Recordset
strSQL = "Select sto_item,Sum(qua_in) as qua from storepro Group By sto_item
rsSto.Open strSQL, DB, adOpenStatic, adLockReadOnly
If rsSto.RecordCount <> 0 Then
rsSto.MoveFirst
With msgList
.Rows = 1
While Not rsSto.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 2) = rsSto("sto_item") & ""
.TextMatrix(.Rows - 1, 3) = qua
rsSto.MoveNext
Wend
End With
End If
但显示qua 为0 ,数据库中值不为0
请帮忙,上面的源程序有何错???谢谢!!
dim qua as double
Set rsSto = New ADODB.Recordset
strSQL = "Select sto_item,Sum(qua_in) as qua from storepro Group By sto_item
rsSto.Open strSQL, DB, adOpenStatic, adLockReadOnly
If rsSto.RecordCount <> 0 Then
rsSto.MoveFirst
With msgList
.Rows = 1
While Not rsSto.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 2) = rsSto("sto_item") & ""
.TextMatrix(.Rows - 1, 3) = qua
rsSto.MoveNext
Wend
End With
End If
但显示qua 为0 ,数据库中值不为0
请帮忙,上面的源程序有何错???谢谢!!
应该在这之前加:qua=rsSto("qua")吧
Dim StrCnn, strSQL As String
Dim rsSto As ADODB.Recordset
Set rsSto = New ADODB.Recordset
StrCnn = 你的数据库连接信息
strSQL = "Select sto_item,Sum(qua_in) as qua from storepro Group By sto_item"
rsSto.Open strSQL, StrCnn, adOpenStatic, adLockReadOnly
If rsSto.RecordCount <> 0 Then
rsSto.MoveFirst
With msgList
.Rows = 1
While Not rsSto.EOF
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 2) = rsSto("sto_item") & ""
.TextMatrix(.Rows - 1, 3) = CStr(rsSto("qua"))
rsSto.MoveNext
Wend
End With
End If