如何在Access中使用SQL语句

如题所述

Sql语句用法如下代码:

    Private Sub Command1_Click()

    Dim sql As String

    Dim l As Integer

    Dim i As Integer

    Dim fieldName() As String

    sql = "select gyh_riqi,sum(shuju1) as hj from jishijilu where gyh_riqi='" & "1000-061210" & "' group by gyh_riqi"

    cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"

    cn.Open

    rs.CursorLocation = adUseClient

    rs.Open sql, cn, adOpenDynamic, adLockOptimistic

    Set DataGrid1.DataSource = rs

    End Sub

    也可赋值给ADO数据控件的RecordSource属性:

    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"

    Adodc1.RecordSource = "select * from jishijilu where shijian like'%81120%' And gyh_riqi like'%10%'"

    Adodc1.Refresh

    Set DataCombo1.RowSource = Adodc1

温馨提示:答案为网友推荐,仅供参考