0
我想使用節點將100k行插入到SQL Server數據庫中。我已經嘗試過使用請求對象的批量方法,但它不會爲我工作。如何使用node.js將數據批量插入到SQL Server中
我的功能,插入到SQL Server數據庫:
var startInsert = function(recordset) {
sql.connect(config,function(err) {
\t \t // console.log(recordset);
\t \t if(err){
\t \t console.log(err);
\t }
\t
\t var table = new sql.Table('ShipmentAuditLogTest');
\t \t recordset.forEach(function(row) {
\t 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);
\t
\t \t });
\t \t var request = new sql.Request();
\t \t request.bulk(table, function(err, rowCount) {
\t \t \t console.log(table);
\t if(err)
\t \t console.log(err);
\t console.log(rowCount);
\t });
});
}
這將返回該錯誤:
{ [RequestError: Incorrect syntax near ')'.]
name: 'RequestError',
message: 'Incorrect syntax near \')\'.',
code: 'EREQUEST',
number: 102,
lineNumber: 1,
state: 1,
class: 15,
serverName: 'FCCHAKANDB',
procName: '',
precedingErrors: [] }
我的記錄:
[ 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: '[email protected]',
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) } ]
你的代碼附近有語法錯誤 –
@Michelem: - 哪裏出錯? –
Ohhh ... sry它是我在複製代碼時的錯誤... –