tompkinsjs
New member
Hi!
I am hoping to get some help with this problem. It seems fairly straight forward, but I just cannot get it to work.
Basically, I am trying to import a text file into a datatable (which can be viewed via a datagridview on a form), then save the imported data to an MS Access database to which the datatable and dataset are bound to. I can get the data from the text file into the datatable (confirmed by viewing it in the datagridview) but I cannot for the life of me get it to save into the MSAccess database. Any help would be appreciated. My code is below.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.ShowDialog()
Dim strFileName As String = OpenFileDialog1.SafeFileName
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\files\;Extended Properties=""Text;HDR=Yes;FMT=Delimited""")
Dim da As New OleDbDataAdapter()
Dim ds As DataSet = Me.InvAnalyzeDataSet
Dim cd As New OleDbCommand("SELECT * FROM " & strFileName, cn)
cn.Open()
da.SelectCommand = cd
da.Fill(ds, "LocalInventory")
cn.Close()
da.Dispose()
InvAnalyzeDataSet.LocalInventory.AcceptChanges()
I have also tried to save the data from the datatable using this:
Me.Validate()
Me.LocalInventoryBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.InvAnalyzeDataSet)
but that does not work either.
Thanks for the help!
I am hoping to get some help with this problem. It seems fairly straight forward, but I just cannot get it to work.
Basically, I am trying to import a text file into a datatable (which can be viewed via a datagridview on a form), then save the imported data to an MS Access database to which the datatable and dataset are bound to. I can get the data from the text file into the datatable (confirmed by viewing it in the datagridview) but I cannot for the life of me get it to save into the MSAccess database. Any help would be appreciated. My code is below.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.ShowDialog()
Dim strFileName As String = OpenFileDialog1.SafeFileName
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\files\;Extended Properties=""Text;HDR=Yes;FMT=Delimited""")
Dim da As New OleDbDataAdapter()
Dim ds As DataSet = Me.InvAnalyzeDataSet
Dim cd As New OleDbCommand("SELECT * FROM " & strFileName, cn)
cn.Open()
da.SelectCommand = cd
da.Fill(ds, "LocalInventory")
cn.Close()
da.Dispose()
InvAnalyzeDataSet.LocalInventory.AcceptChanges()
I have also tried to save the data from the datatable using this:
Me.Validate()
Me.LocalInventoryBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.InvAnalyzeDataSet)
but that does not work either.
Thanks for the help!