Ninleg,
Here is a sample:
I have a Categories.txt file in C:\ that has the following contents:
"Sushi", "All kinds of sushi rolls, including crab tempura roll"
"Wine", "All kinds of wine, including some world famous Australian Shiraz"
To import it into Northwind, create the DataSet and TableAdapters.
Use the following code to import. See comments in code for explanation.
'Opening the file
Using file As New IO.FileStream("C:\Categories.txt", IO.FileMode.Open, IO.FileAccess.Read)
'Creating a strem to read the file into text
Using stream As New IO.StreamReader(file)
'Read the entire file, split it into line arrays by CRLF, and loop through it.
For Each sLine As String In stream.ReadToEnd().Split(Environment.NewLine)
'You to use ", as the delimiter to ensure that commas inside a record are ignored.
Dim sDelimiters() As String = {""","}
'Now split the line into individual records.
Dim sRecords() As String = sLine.Split(sDelimiters, StringSplitOptions.None)
'Insert them into the database by referencing the individual string in the array,
'but be sure to replace the quotes with an emtpy string; otherwise, you will have quote in the record.
'The third argument, to which I'm passing a 'Nothing', is expecting a picture.
CategoriesTableAdapter.Insert(sRecords(0).Replace("""", ""), sRecords(1).Replace("""", ""), Nothing)
Next
End Using
End Using
- Jacob Silberstein
Last edited by jjthebig1; Feb 25th, 2009 at 11:24 pm.