Results 1 to 7 of 7

Thread: ADO.NET And DBase *RESOLVED*

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298

    ADO.NET And DBase *RESOLVED*

    I am connecting to a DBase database and I am not quite sure how to do it through ADO.NET and what the connection string would be.

    Any help would be much appreciated.

    Matt.
    Last edited by MattJH; Jun 26th, 2003 at 10:36 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This is the connection object . All you need is to use Open() method to open the connection . Then you can start filling your dataset through the oleadapter . You need a tutorial...lol
    VB Code:
    1. Private MyPath As String =Application.StartUp & "\yourdatabasefile.mdb"
    2. Private MyPassword As String =Nothing
    3.  
    4. Private My_Connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath & ";Jet OLEDB:database Password=" & MyPassword)

  3. #3
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    You'll need to use an ODBC connection using

    Imports Microsoft.Data.Odbc

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298
    What I have at the moment is the following :

    VB Code:
    1. Imports System
    2. Imports System.Data
    3. Imports System.Data.OleDb
    4. Imports Microsoft.VisualBasic
    5.  
    6. Public Class Form1
    7.     Inherits System.Windows.Forms.Form
    8.  
    9.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    10.         Const strConn As String = "Provider=MSDASQL.1;Persist Security Info=False;Extended Properties=CollatingSequence=ASCII;DBQ=C:\CAL3V305\DBF;DefaultDir=C:\CAL3V305\DBF;Deleted=0;Driver={Microsoft dBase Driver (*.dbf)};DriverId=21;FIL=dBase III;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\DBase.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Statistics=0;Threads=3;UID=admin;UserCommitSync=Yes;"
    11.         Dim objHarleyConnection As New OleDbConnection(strConn)
    12.         Dim objHarleyDA As New OleDb.OleDbDataAdapter("Select * From Labels", objHarleyConnection)
    13.         Dim objHarleyCB As New OleDb.OleDbCommandBuilder(objHarleyDA)
    14.         Dim objHarleyDataSet As New DataSet()
    15.  
    16.         cboHarley.Items.Clear()
    17.  
    18.         Dim i As Integer, strCurrentID As String
    19.  
    20.         For i = 1 To objHarleyDataSet.Tables("Labels").Rows.Count
    21.             strCurrentID = objHarleyDataSet.Tables("Labels").Rows(i - 1).Item("Prod_Desc")
    22.             cboHarley.Items.Add(strCurrentID)
    23.         Next
    24.  
    25.     End Sub
    26.  
    27. End Class

    When I run the program it breaks with the following exception :-

    The .Net Data OLE DB Provider(System.Data.OleDb) does not support the MSDASQL Provider, Microsoft OLE DB Provider for ODBC Drivers.

    I have never really had much need to connect to DBase III files up until now. I can connect to my SQL and Access Databases, but I seem to be at a loss with DBase.

    Cheers.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298
    ggprogram - Imports Microsoft.Data.Odbc <-- I don't seem to have this. Am I missing something???

  6. #6
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    I'm not sure if it will solve your problem, but you can find it by going to Project/Add Reference.

    I don't think you can use OldDb for Dbase files. The following code is excerpted from a test I ran to connect to a mySql database, and might help.

    Imports Microsoft.Data.Odbc

    Sub LoadData()
    Dim MyConString As String
    Dim myConnection As OdbcConnection

    MyConString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;Trusted_connection=true;DATABASE=people;"
    myConnection = New OdbcConnection(MyConString)
    Dim ds As New DataSet()

    ' retrieve a record from a table
    Dim sql As String = "SELECT * FROM names ORDER BY custid"
    Dim da As New OdbcDataAdapter(sql, myConnection)

    da.SelectCommand = New OdbcCommand(sql, myConnection)
    da.Fill(ds, "Names")

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2000
    Location
    Chesterfield, UK
    Posts
    298
    ggprogram, thanks for your help!!!!!

    I didn't have the dll for the odbc on my machine.

    I have downloaded it and your example is great thanks!!!!

    Matt.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width