我用VB做的查询,链接Access数据库,希望对您有帮助
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Private Sub Command5_Click() '将SQL语句已经在Access里实现的查询的结果显示在Text2(3)控件里
cnn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\db_wfcd.mdb"
Set cmd.ActiveConnection = cnn
cmd.CommandText = "select sum(违法面积) from weifa_mingxi where 地块号 in (select 地块号 from weifa_mingxi where 地块号 between '" & Text2(1).Text & "' and '" & Text2(2).Text & "'" & ")"
cmd.CommandType = adCmdText
Set rs = cmd.Execute
Text2(3) = rs(0)
cnn.Close
End Sub