Bulk Record Insert
I need to fetch data from one table (multiple rows) and insert into other table after modifying and adding some new fields.
For example:
Table 1
itemid, price, qnt, date_of_dispatchTable2
Invoiceid, Invoicedate, customer_id, itemid, price, qnt, total_amt, date_of_dispatch, grandtotalPlease help m开发者_StackOverflowe to make it in asp with ms access
Insert the records one by one in the loop over the records from the first table:
Dim oConn1
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "connection string here"
Set oRS = oConn.Execute("Select * From Table1")
Do Until oRS.EOF
strItemId = oRS("item_id")
strPrice = oRS("price")
'....get more data
'....also add new fields like:
Invoicedate = Date()
customer_id = 500
'.......
If Request("confirm_" & strItemId)="1" Then
strSQL = "Insert Into Table2 (itemid, price, customer_id, ...) Values ('" & strItemId & "', '" & strPrice & ', ..."
oConn.Execute(strSQL)
Response.Write("Item " & strItemId & " inserted<br />")
Else
Response.Write("Confirm insert of item " & strItemId & " <input type=""checkbox"" name=""confirm_" & strItemId & """ value=""1"" />")
End If
oRS.MoveNext
Loop
oRS.Close
This is the basic approach, hope it's clear enough.
Edit: added support on confirming every record - now checkbox will appear for each record, and only if the checkbox will be Checked the INSERT statement will take place. This is taking each item_id
as some sort of "key" you can use any other unique value as well.
精彩评论