Not sure if this is possible or not but, I have a comma delimited text file that I am succesfully reading into a datgridview.
I am trying to take the data imported that is in the datagridview and put it in an access db, and an excel file based on the results returned from a combo box (ie. combobox selection is xml, xls, or mdb, etc...)
What I have done so far is set up an acess file, the datatable, and the tableadapter for it. I also creadted another datatable that is bound to the datagridview column names. I then linked the two datatable column names together. It didn't work. Is there another wat to do this
Any help is better than where I am now. I appreciate all your input. Thanks! :)
Here is part of my code...
Dim fileExists As Boolean
fileExists = My.Computer.FileSystem.FileExists("C:\HRExtractWODelimiter.txt")
If fileExists = True Then
My.Computer.FileSystem.DeleteFile("C:\HRExtractWODelimiter.txt", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)
End If
'End check if file exists on C drive
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
OpenFileDialog.Filter = "Text Files (*.txt)|*.txt|Excel CSV Files (*.csv)|*.csv"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
Using myReader As New TextFieldParser(FileName)
myReader.Delimiters = New String() {","}
'Show datagrid and progress bar
DataGridView1.Visible = True
'Try statement to read in parser rows and add to datagrid
Try
While Not myReader.EndOfData 'reads file till end of data
'Perform the increment on the ProgressBar.
ProgressBar1.PerformStep()
Me.DataGridView1.Rows.Add(myReader.ReadFields())
End While 'end of file read
Catch ex As System.Exception 'error catch on non comma delimited file
MsgBox _
("Unable to parse the text file. This program will only parse comma delimited text files." _
& vbCrLf & vbCrLf & vbCrLf & ex.ToString) ' Show friendly error message.
Finally
Beep() ' This line is executed no matter what.
End Try
'End try statement for parser and datagrid add
End Using
End If

Import txt file to DGV export DGV to dB
Venkata Prasad K
cheers! :)
Andy E
If the schema is known and fixed (you know what each item in the CSV is and how many there are per record) then you can design the datatable for access with the same schema as the CSV. It should then just be a matter adding new rows to the datatable for each line parsed out of the CSV.
It will be much easier on you if you don't load the values into the DataGridView to start with. Load them directly into a DataTable then bind the table to the DGV (via a BindingSource is best).
You might also take a look at this thread (http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=517319&SiteID=1) for example code that builds a datatable on the fly based on a delimited file layout and saves a datatable to a delimited file.