G
Guest
I have code that reads and parses a text file using a schema.ini file. Works
great. When I see the dataGrid it's exactly what I want.
Dim CString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\;" & _
"Extended Properties=""text;HDR=No;"""
Dim TConnect As New System.Data.OleDb.OleDbConnection(CString)
TConnect.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from
837P.txt", TConnect)
Dim ds As New DataSet("Bananas")
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
I now want to take this table from the dataGridVew and write it out to my
Access database.
I have code to connect to the db. I can run delete queries against it but I
can't figure out how to add this data to it. I've been all over the internet
and I get close but no joy.
Here's the code I have for the Access half:
Dim objConnection As New OleDbConnection(accessConnect)
'Dim strSQL As String = "Select * INTO z FROM " & table & ";"
Dim strSQL As String = "DELETE text_table.* FROM text_table;"
Dim objCommand As New OleDbCommand(strSQL, objConnection)
Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim objDataTable As New Data.DataTable("text_table")
Dim objDataRow As DataRow
Dim intRowsAffected As Integer
Try
'open db connection
objConnection.Open()
intRowsAffected = objCommand.ExecuteNonQuery()
Catch oledbexceptionerr As Exception
MessageBox.Show(oledbexceptionerr.Message)
End Try
objConnection.Close()
Is there a way to just tweak this code to get it to write my table to
"text_table" in my db?
great. When I see the dataGrid it's exactly what I want.
Dim CString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\;" & _
"Extended Properties=""text;HDR=No;"""
Dim TConnect As New System.Data.OleDb.OleDbConnection(CString)
TConnect.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from
837P.txt", TConnect)
Dim ds As New DataSet("Bananas")
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
I now want to take this table from the dataGridVew and write it out to my
Access database.
I have code to connect to the db. I can run delete queries against it but I
can't figure out how to add this data to it. I've been all over the internet
and I get close but no joy.
Here's the code I have for the Access half:
Dim objConnection As New OleDbConnection(accessConnect)
'Dim strSQL As String = "Select * INTO z FROM " & table & ";"
Dim strSQL As String = "DELETE text_table.* FROM text_table;"
Dim objCommand As New OleDbCommand(strSQL, objConnection)
Dim objDataAdapter As New OleDbDataAdapter(objCommand)
Dim objDataTable As New Data.DataTable("text_table")
Dim objDataRow As DataRow
Dim intRowsAffected As Integer
Try
'open db connection
objConnection.Open()
intRowsAffected = objCommand.ExecuteNonQuery()
Catch oledbexceptionerr As Exception
MessageBox.Show(oledbexceptionerr.Message)
End Try
objConnection.Close()
Is there a way to just tweak this code to get it to write my table to
"text_table" in my db?