Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * form 表名"
Set DataGrid1.datasource = Adodc1
如果是DBF库它的表名是否要加扩展名.DBF?
如果不对,请指出,多谢。

解决方案 »

  1.   

    Dim str As String 
    str = App.Path
    If Right(str, 1) <> "\" Then
    str = str + "\"
    End If
    str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & str & "\data.mdb"
    Adodc1.ConnectionString = str
    Adodc1.CommandType = adCmdText
    Adodc1.RecordSource = "select * from 表"
    Adodc1.Refresh如果是DBF 那么需要改变connectionString
      

  2.   

    你主要是更改连接字符串。你的.dbf文件是什么版本的,是foxpro的还是早期Dbase格式的?
    示例如下:
    使用ADO控件:
    foxpro格式的(.dbf为自由表):
    Private Sub command1_click()
      Dim cnstr As String,sqlstr as string
      cnstr = "Driver={Microsoft Visual FoxPro Driver};" & _
               "SourceType=DBF;" & _
               "SourceDB=;" & app.path & "\data;" & _
               "Exclusive=No"
      adodc1.connectionstring=cnstr
      sqlstr="select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
      adodc1.recordsource=sqlstr
      adodc1.refresh
      Set DataGrid1.DataSource = adodc1
      DataGrid1.Refresh
    End Sub
    以上示例程序的作用是将XXX.dbf表中的数据显示在datagrid1控件中。DBASE格式的:
    Private Sub Form_Load()
      Dim cnstr As String,sqlstr as string
      cnstr = oConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
               "DriverID=277;" & _
               "Dbq=" & app.path & "\data;"
      adodc1.connectionstring=cnstr
      sqlstr="select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
      adodc1.recordsource=sqlstr
      adodc1.refresh
      Set DataGrid1.DataSource = adodc1
      DataGrid1.Refresh
    End Sub以上示例程序的作用是将XXX.dbf表中的各列的第一条记录的各列数据分别显示在不同的textbox控件中。几点说明:app.path是取得应用程序的当明目录,假设你的就用程序目录为:c:\myprg下,数据文件在c:\myprg\data目录下。那么app.path & "\data" 就代表了c:\myprg\data
    即  app.path是取的相对路径,你也可以使用绝对路径c:\myprg\data.
    在你的程序中要将我写的示例程序中相应的地方进行修,如表名,数据源路径等。