Retrieve Data From textfile(.txt) and save it into Access Database

mikanmomo

New member
Joined
Jan 27, 2010
Messages
1
Programming Experience
Beginner
Hi, I am looking for ways to retrieve data from textfile and save it into access database. Currently, I am doing a attendance record project. I need to save the attendance record which is given in a text file to the database.
The version of VB i using is VB 2008.

The content of the text file look like this:
E010,2009/06,06/29/2009 7:44:45AM,06/29/2009 15:00:55PM,JUR
E022,2009/06,06/29/2009 7:44:45AM,06/29/2009 15:00:55PM,JUR
E088,2009/06,06/29/2009 7:44:45AM,06/29/2009 15:00:55PM,JUR
E020,2009/06,06/29/2009 7:44:45AM,06/29/2009 15:00:55PM,JUR
E030,2009/06,06/29/2009 7:44:45AM,06/29/2009 15:00:55PM,JUR

I tried to create a class and store the record but it just don't work. Anyone who can help me? Your help will be greatly appreciated. THANKS!
 
Please post in the most appropriate forum for the topic. This thread has nothing to do with WinForms so it doesn't belong in the WinForms forum. Thread moved.

E.g.
VB.NET:
Using textAdapter As New OleDbDataAdapter("SQL query here", "connection string here")
    Dim table As New DataTable

    textAdapter.AcceptChangesDuringFill = False
    textAdapter.Fill(table)

    Using accessConnection As New OleDbConnection("connection string here")
        Using accessCommand As New OleDbCommand("INSERT statement here", accessConnection)
            With accessCommand.Parameters
                'Add parameters here, e.g.
                .Add("@Name", OleDbType.VarChar, 50, "Name")
            End With

            Using accessAdapter As New OleDbDataAdapter
                accessAdapter.InsertCommand = accessCommand
                accessAdapter.Update(table)
            End Using
        End Using
    End Using
End Using
ConnectionStrings.com can give you the info you need for the connection strings and the text file query.
 
Follow the DW2 linked tutorials in my signature (watching for any pages that are more relevant to your version of VS) to read and write your access DB. Once you can get a stage where you have a datatable that you can load with data and insert, just read the CSV (connectionstrings.com) witha database driver, or a utility library (plenty of CSV readers out there including microsoft's TextFieldParser - reading a CSV is a snippet in visual studio!) and put the data in the datatable, then save it
 
Back
Top