1 我先在设计时将datagrid绑定到adodc控件
然后在一个点击按钮的过程中写了这样的代码
Adodc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
Adodc.CommandType = adCmdText
Adodc.RecordSource = "select * from db1" 
...
但是为什么datagrid控件中显示不出数据呢?
2 我在ADODC的属性设置COMMANDTEXT时老是说语法错,不知道正确的语法是什么?

解决方案 »

  1.   

    '工程-〉引用 Microsoft Active Data Objects 2.x(x表示版本号)
    Dim cn As New ADODB.Connection
    Dim rs As New Recordset
    cn.ConnectionString = "Provider=sqloledb;Data Source=127.0.0.1;Initial Catalog=pubs;User Id=sa;Password=lyjlee;"
    cn.Open
    rs.Open "authors", cn, adOpenKeyset, adLockOptimisticset Adodc.datasource=rs
    Adodc.Refreshrs.close
    cn.close
      

  2.   

    用应用程序向导生成一个数据窗体,里面有代码注意“数据窗体向导”这一步:
    “窗体布局”选择  网格(数据表)
    “绑定类型”选择  ADO数据控件
      

  3.   

    很显然,楼主是想帮定本机的数据库,而不是服务器上的。如果用 date 的话,直接 data1.databasename=app.path
    data1.recordsource="select........"
    data1.refersh
    即可
      

  4.   

    1.
    你的DATAGRID控件和ADODC控件连接了吗?2.
    你的语句是怎么写的!?
      

  5.   

    1 我连接了
    2 select * from 表名
      

  6.   

    1 要加adodc.refresh
     在 Adodc.RecordSource = "select * from db1" 之后加2 正确的语法就是sql语法不过表名最好用[]括起
      

  7.   

    Set SQL = New ADODB.Connection
        Set Rst = New ADODB.Recordset
        If SQL.State > 0 Then
            SQL.Close
        End If
        SQL.Open "Provider=SQLOLEDB.1;Persist Security Info=True;Initial catalog=GPSINFO;Data Source=" & DataServName & ";User ID=" & DBUser & ";Password=" & DBPass & ";"
                                                                          数据库名       机器名        =zhy                         sa                         
      SQL.CommandTimeout = 0 
    '   SQL.Execute "insert into .../select * from db1"
        DBFlg = True
        SQL.Close 
    <datasource> is the name odbc data source as defined on the local system in the odbc configuration utility. CAUTION! the account under which the server is run must be granted permission to access the data source. 
    <user name> is the name which to log into the data source. 
    <password> is the password with which to access the data source.
      

  8.   

    这是一个连接你的机器上 SQL SERVER的语句 在你操作数据库之前 
    1) 凡是你在工程部件中添加的工具,都要到 工程 引用中引用相信的驱动,
    2) 然后你在 用上面的代码连接数据库,
    3) 然后才开始对数据库操作,
    上面的代码中加了判断是否连接成功的语句,(if 中的)
    SQL.Execute" …………"  引号中书写 你的 SQL 语句的命令象现在你用的是Adodc.RecordSource"SQL 语句……"