Solved

loop through access table rows vb.net

Posted on 2012-03-19
2
305 Views
Last Modified: 2012-03-28
Hi guys

 I have a table in a access db it has several fields, but i am only interested in 2.

the first field is uniquekey, this represents the db uniquekey of each track
ie: 3402
     5601
     6507


the second field is filename

which is basically the full path to where the track is stored,
i.e. Filename  D:\Tracks\fff250bd-6c12-4f11-ab9e-a84568a74afb\1cd6e11e-b89e-4899-9aea-31f01401b18c.mp3

I need to copy and rename the files to another folder from all the rows in the table renaming the mp3 files to the uniquekey.

the database name is library
the table is csv

 Could anybody please give me some code to achieve this in vb.net

Best regards

Jimbo
0
Comment
Question by:Jimbo1954
2 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37739136
Fetched from
http://msdn.microsoft.com/en-us/library/dw70f090%28v=vs.80%29.aspx
and
http://msdn.microsoft.com/en-us/library/aa302325.aspx
here is the sample code, please make the necessary changes as and where required:-
    'Set up connection string
    Dim cnString As String
     
    cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Northwind.mdb"
     
    'create command (with both text and connection), change your query accordingly
    Dim sqlQRY As String = "SELECT * FROM tracks"
     
    'Create connection
    Dim conn As OleDbConnection = New OleDbConnection(cnString)
     
    Try
    ' Open connection
    conn.Open()
     
    Dim cmd As OleDbCommand = New OleDbCommand(sqlQRY, conn)
     
    'create data reader
    Dim rdr As OleDbDataReader = cmd.ExecuteReader
     
    While (rdr.Read)
    Dim strTrack as string = rdr("TrackPath").ToString()
    'write this method as per your needs and process the tracks
    ProcessTrack(strTrack);
    End While
     
    Catch ex As SqlException

    Finally
    ' Close connection
    conn.Close()

    End Try

Open in new window

0
 

Author Closing Comment

by:Jimbo1954
ID: 37778459
Thankyou, <br /><br />Jimbo
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question