Bulk Record Insert

霸气de小男生 提交于 2019-12-11 20:36:37

问题


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_dispatch

Table2
Invoiceid,
Invoicedate,
customer_id,
itemid,
price,
qnt,
total_amt,
date_of_dispatch,
grandtotal

Please help me to make it in asp with ms access


回答1:


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.



来源:https://stackoverflow.com/questions/5368842/bulk-record-insert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!