none
Step by Step Connection from DBF to Visual Basic 2008 Express RRS feed

  • Question

  • Im new with VBE2008, but i have to work with a  Foxpro database, I need help to make an aplication connection from Visual Basic 2008 Express
    Thursday, October 22, 2009 5:23 AM

Answers

  • You can only connect to a FoxPro database using code. Visual Basic Express Edition doesn't support this database when using the data wizards. In code you can use the FoxPro OLEDB Provider or Microsoft OLEDB Provider and the dBase ISAM. Below is an example:

            Dim ConnectionString As String
    
            ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=e:\My Documents\dBase;Extended Properties=dBase IV"
            Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
            dBaseConnection.Open()
    
            Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM MyDBase", dBaseConnection)
            Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)
    
            While dBaseDataReader.Read
                Console.WriteLine(dBaseDataReader("Column1").ToString)
                Console.WriteLine(dBaseDataReader("Column2").ToString)
                Console.WriteLine(dBaseDataReader("Column3").ToString)
            End While
    
            dBaseConnection.Close()
    



    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Marcoahs Friday, October 23, 2009 3:42 PM
    Thursday, October 22, 2009 8:44 PM

All replies

  • Here is an article with samples

    http://msdn.microsoft.com/en-us/library/aa977092(VS.71).aspx

    Val Mazur (MVP) http://www.xporttools.net
    Thursday, October 22, 2009 10:06 AM
    Moderator
  • Hello VMAzur, I have read the article but in Visual Basic 2008 Express I dont have Server Explorer I have Solution Explorer and Data Origins and when I try to add a database it only lets me 3 types.
    Microsoft Access
    Microsoft SQL Server
    Microsoft SQL Server Compact 3.5

    I Have all ready Installed the Foxpro OLE DB Provider for Visual Fox 9.0 but it dosent show.

    What am I missing?
    Thursday, October 22, 2009 4:45 PM
  • You can only connect to a FoxPro database using code. Visual Basic Express Edition doesn't support this database when using the data wizards. In code you can use the FoxPro OLEDB Provider or Microsoft OLEDB Provider and the dBase ISAM. Below is an example:

            Dim ConnectionString As String
    
            ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=e:\My Documents\dBase;Extended Properties=dBase IV"
            Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
            dBaseConnection.Open()
    
            Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM MyDBase", dBaseConnection)
            Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)
    
            While dBaseDataReader.Read
                Console.WriteLine(dBaseDataReader("Column1").ToString)
                Console.WriteLine(dBaseDataReader("Column2").ToString)
                Console.WriteLine(dBaseDataReader("Column3").ToString)
            End While
    
            dBaseConnection.Close()
    



    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Marked as answer by Marcoahs Friday, October 23, 2009 3:42 PM
    Thursday, October 22, 2009 8:44 PM
  • Oh, and below is a link that contains connection string examples for using the Visual FoxPro OLEDB Provider:

    http://www.connectionstrings.com/visual-foxpro


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Thursday, October 22, 2009 8:47 PM
  • Thanks a Million, it's Working now Paul P Clement IV.

    Would it be to much to ask if you could tell me how to fill a Data Grid with the data in a table?
    Friday, October 23, 2009 3:45 PM
  • Below is another example which uses a DataAdapter:

            ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=C:\Documents and Settings\...\My Documents\My Database\dbase;Extended Properties=dBase IV"
            Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
            dBaseConnection.Open()
    
            Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("SELECT * FROM Orders", dBaseConnection)
            Dim dBaseAdapter As New System.Data.OleDb.OleDbDataAdapter
            dBaseAdapter.SelectCommand = dBaseCommand
            Dim dBaseDataTable As New DataTable
            dBaseAdapter.Fill(dBaseDataTable)
    
            frmMain.DataGrid1.DataSource = dBaseDataTable
    
            dBaseConnection.Close()

    Paul ~~~~ Microsoft MVP (Visual Basic)
    Friday, October 23, 2009 4:47 PM