如何用VB打开DBF数据库
查询呢?
谢谢高分想送

解决方案 »

  1.   

    可以用ODBC先连接数据库,再用VB连接ODBC
      

  2.   

    data1.Connect = "foxpro 2.6;"
    data1.DatabaseName = 数据库物理路径
    data1.RecordSource = 数据库名
    data1.Refresh
      

  3.   

    在控制面板中打开ODBC,选择添加,选择Driver dBase VFP Driver (*.dbf),完成,给这个连接起一个名字,比如:MyDate,浏览你的数据库位置。完成。在工程中添加ADO控件,设置其连接字符串为"Provider=MSDASQL.1;Persist Security Info=False;Data Source=MyDate"把Text控件绑定到Ado
      

  4.   

    cnstr ="Driver={Microsoft Visual FoxPro Driver};" & _
               "SourceType=DBF;" & _
               "SourceDB=app.path & "d:\bacp\no1\;" & _
               "Exclusive=No"
      cn.Open cnstr这里哪里错了呢~?请高手指教~
    8095856是我的QQ
      

  5.   

    我这里有一个VB连接数据库的例子,全部用代码,不直接采用控件,如需要我可以发给你。
    我的电子邮件:[email protected]
    如需要请给我发电子邮件
      

  6.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fox7help/html/dggrfOLEDBProviderforVisualFoxPro.asp
      

  7.   

    To access Visual FoxPro data in Visual Studio Establish a connection object, create a data object, specify the OLE DB Provider and the data source in a connection string, and then access and manipulate data using appropriate properties and methods. 
    ADOIn Visual FoxPro this access looks like this:   OConn = CREATEOBJECT("ADODB.Connection")
       OConn.ConnectionString = "provider=vfpoledb.1;;
          data source=.\testdbc.dbc"
       OConn.Open
    In Visual Basic 6.0, access takes the following form:   Sub ADOOpenVFPDatabase()
          Dim cnn As New ADODB.Connection
          cnn.Open "Provider=vfpoledb;" & _
             "Data Source=.\TasTrade.dbc;"
          cnn.Close
       End Sub
    For a complete explanation of connection string syntax, see the Microsoft OLE DB 2.5 Programmer's Reference and SDK Guide.
      

  8.   


    OConn.ConnectionString = "provider=vfpoledb.1;;
          data source=.\testdbc.dbc"
      

  9.   

    TO天外来客对不起,我要求的是打开DBF的
    按照你表单,可以统计吗?比如多少男女?
    你能改一一下吗谢谢了
    其他的,我其在是没有看明白什么意思
      

  10.   

    可以引用ADO对象来搞定。
    你首先要在VB菜单中:
    “工程”-->“引用”-->“Microsoft AxtiveX Data Objects 2.1 Library”
    示例:Private Sub Form_Load()
      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      Dim cnstr As String
      cnstr = "Driver={Microsoft Visual FoxPro Driver};" & _
               "SourceType=DBF;" & _
               "SourceDB=" & app.path & "\data;" & _
               "Exclusive=No"
      cn.Open cnstr
      rs.CursorLocation = adUseClient
      rs.Open "select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
      Set DataGrid1.DataSource = rs
      DataGrid1.Refresh
    End Sub以上示例程序的作用是将XXX.dbf表中的数据显示在datagrid1控件中。
      

  11.   

    以上的.dbf文件是VFP的。
    如果你的dbf文件是早期版的dbase格式的话那么就将连接字符串更改一下。记得使用本程序要先引用ADO对象。(引用方法见上)
    示例:Private Sub Form_Load()
      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      Dim cnstr As String
      cnstr = oConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
               "DriverID=277;" & _
               "Dbq=" & app.path & "\data"
      cn.Open cnstr
      rs.CursorLocation = adUseClient
      rs.Open "select * from XXX.DBF", cn, adOpenKeyset, adLockBatchOptimistic
      text1.text=trim(rs.Fields(0))
      text2.text=trim(rs.fields(1))
      .......
      text6.text=trim(rs.fields(5))
    End Sub以上示例程序的作用是将XXX.dbf表中的各列的第一条记录的各列数据分别显示在不同的textbox控件中。几点说明:app.path是取得应用程序的当明目录,假设你的就用程序目录为:c:\myprg下,数据文件在c:\myprg\data目录下。那么app.path & "\data" 就代表了c:\myprg\data
    即  app.path是取的相对路径,你也可以使用绝对路径c:\myprg\data.
    在你的程序中要将我写的示例程序中相应的地方进行修,如表名,数据源路径等。
      

  12.   

    我来说说:
    用DAO方式只能打开3.0及以下版本的DBF表,可以执行一切SQL语句对于以上的就无能为力了;
    而对于ADO方式,不管是用ODBC,OLE DB或是用MS VISAUL FOXPRO DRIVER都可以连接上,但要执行导出到另外的表或是导出到新表或是执行用一个表的数据更新另外一个表的数据就没有用,是不行的,不能执行.
    以上是我个人的观点且已试过,不苟同者大家可以讨论讨论