Read and navigate a csv file

Slider

Member
Joined
Jun 11, 2009
Messages
22
Programming Experience
Beginner
Hi, as you can tell I am new to VB.net (first post so be gentle). I am wanting to create an application to read a csv file (chosen by the user) and then display the contents in text boxes. I would also like navigation buttons allowing the user to navigate through the csv (textboxes to reflect the new record). I originally started this project in VB6, but have now moved onto VB.net. Can someone give me any pointers please?

Thank you.
 
As a first step you'll want to get the information from the csv file into a DataSet. The easiest way would be to use ADO.NET.

VB.NET:
Expand Collapse Copy
Dim connection As New OleDbConnection("your connection string here")
Dim dataAdapter As New OleDbDataAdapter("your SQL query here", connection)
Dim dataTable As New DataTable
adapter.Fill(dataTable)

I'd start looking here for the connection string portion of the code: ConnectionStrings.com - Forgot that connection string? Get it here!

As an alternative you can look into using a TextFieldParser object to navigate the fields.
 
As a first step you'll want to get the information from the csv file into a DataSet. The easiest way would be to use ADO.NET.

VB.NET:
Expand Collapse Copy
Dim connection As New OleDbConnection("your connection string here")
Dim dataAdapter As New OleDbDataAdapter("your SQL query here", connection)
Dim dataTable As New DataTable
adapter.Fill(dataTable)

I'd start looking here for the connection string portion of the code: ConnectionStrings.com - Forgot that connection string? Get it here!

As an alternative you can look into using a TextFieldParser object to navigate the fields.

Hi, thank you for that. Been looking on MSDN about the TextFieldParser and it seems good. Got an example which loads csv and parses the string into fields. Just need to amend to allow the file to come from user input, not a fixed filename. How do I navigate forwards/backwards though within the csv?
 
Add a DataSet to your project, add a table to your dataset, show the Data Sources window, set the mode for your table to Details, drag the table to the form.

Here is the DS window showing a table that the user is about to set to details:
vb.4.7_big.gif
 
Prices start from $195, when a free connection string will do the same job? C'mon! I'm all for paying for something when it's worth it for the task at hand (i.e. visual studio)
 
The SDK can be better if you need to minimize load time and plan to read XLS, XLSX, ODS files in the future. If you don't plan to read other formats and speed is not critical for you, then using ODBC drivers can be enough (and free! :))
 
Back
Top