M
Marc Scirri
I have populated a data table (dtHeader) from a SQL database using a SQL
Data Adapter. I have an Access table (header) with the same fields as the
SQL table. I want to populate the Access table with the data in the data
table. The data table contains information from multiple SQL tables with teh
same schema.
I am currently attempting to run an InsertCommand from an OleDB DataAdapter
for each row of the data table to get teh data into Access 1 row at a time.
I ahve to do this for 5 tables andit is going to be a lot of code to create
and assign values to all of the parameters.
Is there an easier way to populate the Access table, with all of the data
tables rows at once even?
----------------------------------------
Dim sdaROW as new SqlClient.SqlDataAdapter, cmdSQL as New
SqlClient.SqlCommand
Dim conOLE as new Data.OleDb.OleDbConnection, cmdOLE as new
OleDb.OleDbCommand
Dim odaROW as new OleDb.OleDbDataAdapter, odrROW as OleDb.OleDbDataReader
conOLE.ConnectionString = sConString
conOLE.Open()
' Populate the data table with the SQL data
sdaROW.SelectCommand = new SqlClient.SqlCommand
with sdaROW
.SelectCommand.Connection = scnFD
.SelectCommand.CommandText = "SELECT * FROM " & sSelectSQL
.Fill(dtHeader)
.SelectCommand = nothing
end with
sdaROW = nothing
odaROW.InsertCommand = new OleDb.OleDbCommand
odaROW.InsertCommand.Connection = conOLE
odaROW.InsertCommand.CommandText = "INSERT INTO header (guid, parentguid)
VALUES (?,?)"
odaROW.InsertCommand.Parameters.Add("guid",OleDb.OleDbType.Guid,64,"guid")
odaROW.InsertCommand.Parameters.Add("parentguid",OleDb.OleDbType.Guid,64,"pa
rentguid")
for iCounter = 0 to dtHeader.Rows.Count - 1
odaROW.InsertCommand.Parameters.Item("guid") =
dtHeader.Rows(iCounter).Item("guid")
odaROW.InsertCommand.Parameters.Item("parentguid") =
dtHeader.Rows(iCounter).Item("parentguid")
odaROW.InsertCommand.ExecuteNonQuery()
next iCounter
Data Adapter. I have an Access table (header) with the same fields as the
SQL table. I want to populate the Access table with the data in the data
table. The data table contains information from multiple SQL tables with teh
same schema.
I am currently attempting to run an InsertCommand from an OleDB DataAdapter
for each row of the data table to get teh data into Access 1 row at a time.
I ahve to do this for 5 tables andit is going to be a lot of code to create
and assign values to all of the parameters.
Is there an easier way to populate the Access table, with all of the data
tables rows at once even?
----------------------------------------
Dim sdaROW as new SqlClient.SqlDataAdapter, cmdSQL as New
SqlClient.SqlCommand
Dim conOLE as new Data.OleDb.OleDbConnection, cmdOLE as new
OleDb.OleDbCommand
Dim odaROW as new OleDb.OleDbDataAdapter, odrROW as OleDb.OleDbDataReader
conOLE.ConnectionString = sConString
conOLE.Open()
' Populate the data table with the SQL data
sdaROW.SelectCommand = new SqlClient.SqlCommand
with sdaROW
.SelectCommand.Connection = scnFD
.SelectCommand.CommandText = "SELECT * FROM " & sSelectSQL
.Fill(dtHeader)
.SelectCommand = nothing
end with
sdaROW = nothing
odaROW.InsertCommand = new OleDb.OleDbCommand
odaROW.InsertCommand.Connection = conOLE
odaROW.InsertCommand.CommandText = "INSERT INTO header (guid, parentguid)
VALUES (?,?)"
odaROW.InsertCommand.Parameters.Add("guid",OleDb.OleDbType.Guid,64,"guid")
odaROW.InsertCommand.Parameters.Add("parentguid",OleDb.OleDbType.Guid,64,"pa
rentguid")
for iCounter = 0 to dtHeader.Rows.Count - 1
odaROW.InsertCommand.Parameters.Item("guid") =
dtHeader.Rows(iCounter).Item("guid")
odaROW.InsertCommand.Parameters.Item("parentguid") =
dtHeader.Rows(iCounter).Item("parentguid")
odaROW.InsertCommand.ExecuteNonQuery()
next iCounter