It seems to me impossible to do a very simple thing as to connect to a MDB or to a TXT file as a record source using the wizard (It's VISUAL BASIC isn't it )
From the Data Source Configuration Wizard
--> New Connection
--> changed the data source to MS Access but ...
the system does NOT show me the windows to let me browse the file I want and I am shown only an input line space for a connection string, no other possibilities are given.
Nevertheless I tried a conncection string syntax I found on internet "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb"
but nothing of nothing, no way to come to a point...
I DO NOT WANT TO SET UP SQL DATABASE TO STORE A FEW RECORDS,
anyone has an idea how to connect to a popular Ms Access database in VB Express Thanks a lot for any suggestion, Mike

MS Access connection problem
John_Cronan
Hi Mike,
I had a lot of trouble with general updatting of Access Databases in ADO.NET but one thing I've been able to is to add records and that seems to be what you need.
These declarations are in a common module
Imports
System.DataPublic con As OleDb.OleDbConnection = New OleDb.OleDbConnection(GetConnectionString)
Public Adapter As OleDb.OleDbDataAdapter
Public Dataset As New DataSet
Imports
System.DataHere is my GetConnectionString Routine
Public Function GetConnectionString() As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file.
Const cKnowlegeStore As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""H:\aa\DatabasePrimitives\DatabasePrimitives\KnowledgeStore.mdb"""
Return cKnowlegeStore
End Function
This works and will help you populate your database.
Public Function InsertRecord(ByVal NewRow As DataRow, ByVal Table As DataTable) As Boolean
'works
NewRow(0) = Table.Rows.Count ' Autoincrement
Table.Rows.InsertAt(NewRow, Table.Rows.Count)
Using CmdBuilder As New OleDbCommandBuilder(Adapter)
Try
With Adapter
.SelectCommand = New OleDbCommand("Select * from [" & Table.TableName & "]", con)
.InsertCommand = CmdBuilder.GetInsertCommand
.UpdateCommand = CmdBuilder.GetUpdateCommand
.DeleteCommand = CmdBuilder.GetDeleteCommand
End With
con.Open()
Adapter.Update(Table)
con.Close()
Dataset.AcceptChanges()
Return True
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Exclamation, "ADONET.InsertRecord")
Return False
End Try
End Using
End Function
Here's what to when you need a row....
Public Function GetNewRecord(ByVal Table As DataTable) As DataRow< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
GetNewRecord = Nothing
Try
Return Dataset.Tables(Table.TableName).NewRow()
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Exclamation, "ADONET.GetNewRecord")
End Try
End Function
Honest to goodness, I’ve had trouble with other updates, but this does work.
Good luck!
csexpert
ok but when I change the data source to MDB the only thing I can do is type in as "connection string" and I could not find a good one to work !!
Mike
salvatore
hi,
i guess jmcilhinney answered the question but i just want to add one point
6) when the wizard ask you to import the database to your project hit no
or other wise you can write your connection
Dim dbconn as oledbconnection
Dim dbcomm as oledbcommand
Dim dbreader as oledbdatareader
Dim sqlstr as string
dbconn = new oledbconnection("provider=microsoft.jet.oledb.4.0;data source=full path to your database")
dbconn.open()
sqlstr = "select * from products order by itemnumber"
dbcomm = new oledbcommand(sqlstr, dbconn)
dbreader = dbcomm.executereader()
While DBreader.Read()
'do some stuff
End while
dbreader.close()
dbconn.close()
hope this helps
rdmorgan
Here are the steps that i took:
dozaone
Well... I have a diferent problem.
I connected the Database using the Wizard, remember that it creates:
-DataSet
When you add a DataGridViewer other elements are created:
-BindingSource
-DataAdapter
I did charge in the DataAdapter the contain from a Text File and when I use the .Fill command the Information loaded appears but I don’t know how to transfer the information into the physical database (Access of course).
Do you have any idea
glw
Just an FYI, you can't create a data source connection to a TXT file using the Data Source Configuration Wizard. You can only use code. There is an example in the below newsgroup link:
http://tinyurl.com/9c8eg
Otherwise the steps posted by jmcilhinney for an Access database should work for you.
jooolaaab
David Winningham
Ieeeeeeeeeeeee
J,
That's the first thing I've ever seen you say that I disagree with, not because it's wrong but because it removes us from code. I really don't like drawing a database or the clicking because I don't know what the code is doing.
I will choose to initialize my own datastructures etc, just so I can understand what's occuring.