用于将项目插入Windows Azure中的其他表的脚本

时间:2013-08-16 14:46:56

标签: javascript sql windows azure

我刚开始使用Windows Azure进行开发。到目前为止这么好,但我遇到了一个非常基本的问题:如何将项目从移动服务脚本插入到不同的表中?我在Windows Azure博客上找到的代码似乎不像宣传的那样工作:

function insert(item, user, request) {

    var currentTable = tables.getTable('current'); // table for this script
    var otherTable = tables.getTable('other'); // another table within the same db

    var test = "1234";
    request.execute(); // inserts the item in currentTable

    // DOESN'T WORK: returns an Internal Server Error
    otherTable.insert(test, {
                        success: function()
                        {

                        }
    });
}

知道我做错了什么或者我在哪里可以找到使用语法的帮助?谢谢!

1 个答案:

答案 0 :(得分:0)

在另一个从未出现过的StackOverFlow帖子上找到答案,典型的... 我做错的事情是没有提供要更新的列的名称。所以不要:

var test = "1234";
// DOESN'T WORK because no column is declared
otherTable.insert(test, {
                    success: function()
                    {

                    }
});

我应该有:

var test = {code : "1234"};
// WORKS because the script knows in what column to store the data 
// (here the column is called "code")
otherTable.insert(test, {
                    success: function()
                    {

                    }
});

所以给出完整正确的代码:

function insert(item, user, request) {

    var currentTable = tables.getTable('current'); // table for this script
    var otherTable = tables.getTable('other'); // another table within the same db

    var test = {code: "1234"};
    request.execute(); // inserts the item in currentTable

    otherTable.insert(test, {
                    success: function()
                    {

                    }
    }); // inserts test in the code column in otherTable
}