VB 程序连VFP数据库不支持聚合函数???
Private Sub Command1_Click()
Dim sql1 As String
Dim sql2 As String
Dim rsResult As New ADODB.Recordset
'Open connection to Temp Folder
Dim cndbf As ADODB.Connection
Set cndbf = New ADODB.Connection
cndbf.ConnectionString = "Provider=VFPOLEDB;Data Source=D:\TestVbp\Temp\Hiport.dbc"
cndbf.CursorLocation = adUseClient
cndbf.Open
sql1 = "Select * from z_Valuation Where Currency = 'CNY' "
sql2 = "Select currency, sum(LqValue*Exch) as PValue from z_Valuation Where Currency = 'CNY' group by currency"
rsResult.Open sql1, cndbf, adOpenForwardOnly, adLockBatchOptimistic
If Not rsResult.EOF Then
MsgBox "RecordCount = " & rsResult.RecordCount
Else
MsgBox "NO Record!"
Exit Sub
End If
rsResult.Close
rsResult.Open sql2, cndbf, adOpenForwardOnly, adLockBatchOptimistic
If Not rsResult.EOF Then
MsgBox "RecordCount = " & rsResult.RecordCount
Else
MsgBox "NO Record!"
Exit Sub
End If
rsResult.Close
End Sub
sql1可以选出一条记录,sql2为什么不能选出记录呢???
[解决办法]
安装最新的驱动试试:
Microsoft OLE DB Provider for Visual FoxPro 9.0
oledb for vfp下载地址:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14839
Version: 1.2
Date Published: 5/16/2008
Language: English
File Name Size
vfpoledb.msm 829 KB
VFPOLEDBSetup.msi 1.0 MB (安装此项)
[解决办法]
Dim dd As New ADODB.Connection
Dim dd1 As New ADODB.Recordset
dd.Open ("Provider=VFPOLEDB.1;Data Source=r:\temp;")
dd1.Open "Select [currency], cast(sum(Value*Exch) as n(12,2) ) from test!testgroup Where Currency = 'CNY' group by [currency]", dd, adOpenDynamic, adLockOptimistic
Do While Not dd1.EOF
MsgBox dd1(0) & " 123 " & dd1(1)
dd1.MoveNext
Loop
测试没有问题