节点mssql服务器循环并插入

时间:2015-10-12 18:57:57

标签: javascript sql-server node.js

您好我在使用mssql包,我让它适用于一个插件,但是当我尝试在每个循环后插入时它会中断或不插入任何内容。它似乎可以解决插入连接问题。我已经尝试将它放入一个单独的函数中,但这也不起作用。其他人尝试这样的事情。也许是全球联系,但不知道如何使用它。

        dbconfigDemo = {
            server: "IP HERE",
            database: "DB",
            user: "Username",
            password: "passwordhere",
            port: 1433,

        }

            // Problems Section
            for (i = 0; i < ccda.data.problems.length; i++) {
            //loop each problem
                Problems = ccda.data.problems[i];

                var connection = new sql.Connection(dbconfigDemo, function(err) {
                var request = new sql.Request(connection); 

                 //Set variables here to use in insert   
                DOCUMENT_OID = Problems.age;
                PROBLEM_DOCUMENT_EXTENSION_ID = Problems.name;

              ");

                    request.query("INSERT INTO PROBLEM (DOCUMENT_OID,PROBLEM_DOCUMENT_EXTENSION_ID)" +
                    "VALUES (" +
                    "'" + DOCUMENT_OID + "'," +
                    "'" + PROBLEM_DOCUMENT_EXTENSION_ID + "'," +

                    });
                    //close the connection
                    connection.close();
                });

            }

0 个答案:

没有答案