Hi All
I am not that experienced. I am using VB Express 2008. I have a problem. I am importing a csv file in a datagrid with the following code :
Private Sub btnFindFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindFile.Click
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
OpenFileDialog.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*"
OpenFileDialog.Title = "Select A CSV File"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = IO.Path.GetFileName(OpenFileDialog.FileName)
Dim Path As String = IO.Path.GetDirectoryName(OpenFileDialog.FileName)
Dim connString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" _
& Path & ";Extended Properties=""Text;HDR=No;FMT=Delimited"""
Dim conn As New Odbc.OdbcConnection(connString)
Dim da As New Odbc.OdbcDataAdapter("SELECT * FROM [" & FileName & "]", conn)
Dim dt As New DataTable
da.Fill(dt)
ItemsDataGridView.DataSource = dt
End If
End Sub
The code is working perfectly, and display all the content of the csv file in my datagrid. My problem is the following: I cannot figure out how to save the imported info in the datagridview, to my mdb database.
I have tried the following, but with no luck :
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet1.Items)
Me.Validate()
Me.ItemsBindingSource.EndEdit()
Any help would be appreciated.
Maybe I should just mention: I am trying to save into an existing Access mdb database, where the table has more columns than the imported csv file.