批量记录插入

发布于 2024-10-23 23:24:30 字数 283 浏览 8 评论 0原文

我需要从一个表(多行)中获取数据,并在修改和添加一些新字段后插入到其他表中。

例如:

表 1
项目ID,
价格,
qnt,
date_of_dispatch

表2
发票编号,
发票日期,
客户 ID,
项目ID,
价格,
qnt,
总金额,
发货日期,
grandtotal

请帮我用 ms access 制作它

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-10-30 23:24:30

在循环中逐条插入第一个表中的记录:

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

这是基本方法,希望它足够清楚。

编辑:添加了对确认每条记录的支持 - 现在每条记录都会出现复选框,并且仅当选中该复选框时才会发生 INSERT 语句。这将每个 item_id 作为某种“键”,您也可以使用任何其他唯一值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文