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.
Printable View
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.
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:
Private MyPath As String =Application.StartUp & "\yourdatabasefile.mdb" Private MyPassword As String =Nothing Private My_Connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath & ";Jet OLEDB:database Password=" & MyPassword)
You'll need to use an ODBC connection using
Imports Microsoft.Data.Odbc
What I have at the moment is the following :
VB Code:
Imports System Imports System.Data Imports System.Data.OleDb Imports Microsoft.VisualBasic Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 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;" Dim objHarleyConnection As New OleDbConnection(strConn) Dim objHarleyDA As New OleDb.OleDbDataAdapter("Select * From Labels", objHarleyConnection) Dim objHarleyCB As New OleDb.OleDbCommandBuilder(objHarleyDA) Dim objHarleyDataSet As New DataSet() cboHarley.Items.Clear() Dim i As Integer, strCurrentID As String For i = 1 To objHarleyDataSet.Tables("Labels").Rows.Count strCurrentID = objHarleyDataSet.Tables("Labels").Rows(i - 1).Item("Prod_Desc") cboHarley.Items.Add(strCurrentID) Next End Sub 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.
ggprogram - Imports Microsoft.Data.Odbc <-- I don't seem to have this. Am I missing something???
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")
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.