MS Access and VB.NET

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

I am attempting to automate the process within a vb.net windows application
of importing a text file into an access database (setting the column
seperators, first row being column names and such) but I am not finding
examples of this on the net? Has anyone ran across such a thing?
 
* "scorpion53061 said:
I am attempting to automate the process within a vb.net windows application
of importing a text file into an access database (setting the column
seperators, first row being column names and such) but I am not finding
examples of this on the net? Has anyone ran across such a thing?

Did you have a look at <URL:http://www.connectionstrings.com/>?
 
How does this help with importing text files into MS Access? What I am
trying to do is code an action that duplicates the MS Access Import Wizard
we use when we want to import a text file into access?
 
Hi scorpion,
You probably have a CSV file that you want to import to Database. Here is an
example how to fill datatable from CSV file. It will get you started

Private Sub ConnectToText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Handles ConnectToText.Click

'Establish a connection to the data source.
Dim sConnectionString As String

sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=d:\My Documents\TextFiles;Extended
Properties=Text;"
Dim objConn As New
System.Data.OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from
People.txt", objConn)

Dim ds As New DataSet("PeopleFile")

da.Fill(ds, "People.txt")

Dim dt As DataTable
dt = ds.Tables("People.txt")

Dim drCurrent As DataRow
For Each drCurrent In dt.Rows
Console.WriteLine("{0} {1}", _
drCurrent("0").ToString, _
drCurrent("1").ToString)
Next

objConn.Close()

End Sub

scorpion53061 said:
How does this help with importing text files into MS Access? What I am
trying to do is code an action that duplicates the MS Access Import Wizard
we use when we want to import a text file into access?
 
* "scorpion53061 said:
How does this help with importing text files into MS Access? What I am
trying to do is code an action that duplicates the MS Access Import Wizard
we use when we want to import a text file into access?

Yep. One approach is to load data from the text file and then insert it
in Access.
 
¤ How does this help with importing text files into MS Access? What I am
¤ trying to do is code an action that duplicates the MS Access Import Wizard
¤ we use when we want to import a text file into access?
¤

You don't really need to use automation with MS Access to do this:

Function ImportTextToAccess() As Boolean

Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=d:\My Documents\db1.mdb")

AccessConn.Open()

'New table
'Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [tbl1] FROM
[Text;DATABASE=d:\My Documents\TextFiles].[CSV.txt]", AccessConn)
'Existing table
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [tbl1] (F1, F2, F3, F4,
F5) SELECT F1, F2, F3, F4, F5 FROM [Text;DATABASE=d:\My Documents\TextFiles;].[CSV.txt]",
AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()

End Function


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
These answers have all been helpful.

Thank you especially Herfried for not understanding what you were getting at
before.

scorpion53061 said:
How does this help with importing text files into MS Access? What I am
trying to do is code an action that duplicates the MS Access Import Wizard
we use when we want to import a text file into access?
 
Hi Scorpion,

Than it is easy, just read it and put it in a field.

I had already made a serialise routine for you to do it with a doc file and
I did thought that without asking if that was needed you would probably not
have understanded it why I did it that difficult.

Cor
 
I've never tried to do this myself, but I suspect you're going to have
to use automation and invoke a VBA procedure in the mdb to do it.

--Mary
 
Hi Mary,

Would you know where to go to find an example of this?
That is kind of where I was headed originally.
 
Try one of the microsoft.public.msaccess newsgroups that deal with
programming since you'll need to use VBA.

--Mary
 
Back
Top