簡體   English   中英

如何使用node.js將數據批量插入SQL Server

[英]How to bulk insert data into SQL Server using node.js

我想使用節點將10萬行插入到SQL Server數據庫中。 我已經使用請求對象的批量方法嘗試了它,但是對我來說不起作用。

我要插入SQL Server數據庫的函數:

 var startInsert = function(recordset) { sql.connect(config,function(err) { // console.log(recordset); if(err){ console.log(err); } var table = new sql.Table('ShipmentAuditLogTest'); recordset.forEach(function(row) { table.rows.add(row.ShippingID,row.BagNo,row.ProcessLocation,row.Process,row.Comment,row.CreatedDate,row.CreatedBy,row.LastModifiedDate,row.LastModifiedBy,row.DestinationLocation,row.VenderLostShipmentsDebitId); }); var request = new sql.Request(); request.bulk(table, function(err, rowCount) { console.log(table); if(err) console.log(err); console.log(rowCount); }); }); } 

這將返回此錯誤:

{[RequestError:')'附近的語法不正確。]
名稱:“ RequestError”,
消息:'\\')\\'附近的語法不正確。',
代碼:“ EREQUEST”,
數:102,
lineNumber:1
狀態:1
班級:15
serverName:“ FCCHAKANDB”,
procName:”,
previousErrors:[]}

我的記錄集:

[ RowDataPacket {
    ShippingID: '2FX880141',
    BagNo: 'CHKXFL1808362',
    ProcessLocation: '2',
    Process: 'BagIn',
    Comment: 'Shipment added in ParentBagNo: CHKXFL1808362',
    CreatedDate: Tue Apr 07 2015 16:36:18 GMT+0530 (India Standard Time),
    CreatedBy: 'support@firstcry.com',
    LastModifiedDate: '0000-00-00 00:00:00',
    LastModifiedBy: 'null',
    DestinationLocation: 'null',
    VenderLostShipmentsDebitId: 0,
    InsertedTime: Mon Dec 14 2015 14:26:16 GMT+0530 (India Standard Time) } ]

萬一其他人偶然發現了這個問題,我想出了我的錯誤,以及對您來說可能是什么問題。

多虧了我發現的另一個問題 ,我才意識到我的錯誤是我正在插入要添加到現有表中的行,但是您還必須插入要插入的表中的列。 看來這就是您的問題所在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM