Hi
I have a datatable which I want to write to a table in my database.
What I want to do is copy the results of this datatable into a table in my database.
Something like…
I’m not sure if this is the best way to do this or how to end my INSERT INTO statement to incorporate my datatable.
Any ideas would be gratefully received.
I have a datatable which I want to write to a table in my database.
Code:
Dim varSQL As String
varSQL = ("SELECT * FROM [tblCost] WHERE [Part Number] = '" & txtPartNumber.Text & "' ORDER BY [Part Number]")
Try
Dim AccessCommandPartRetrieve As New System.Data.OleDb.OleDbDataAdapter(varSQL, AccessConn)
Dim dt As DataTable
dt = New DataTable
AccessCommandPartRetrieve.Fill(dt)
AccessConn.Close()
…
What I want to do is copy the results of this datatable into a table in my database.
Something like…
Code:
AccessConn.Open()
Dim AccessCommandInsert As New System.Data.OleDb.OleDbCommand("INSERT INTO [tblMarkUp] ([Record Type], [Part Number], Description, [Procurement Type], BOM, Component, Node, [Valid From], [Qty Per], [Raw Material], [Sub Contract], [Material Overhead], [Direct Labour], [Labour Overhead], [Factory Overhead])
** and then the values in the datatable!
Try
With AccessCommandInsert
.Connection = AccessConn
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
AccessConn.Close()
…
I’m not sure if this is the best way to do this or how to end my INSERT INTO statement to incorporate my datatable.
Any ideas would be gratefully received.