如何在 asmx Web 服务中返回多个数据库行

发布于 2024-08-12 10:45:01 字数 56 浏览 2 评论 0原文

我可以在网络服务中返回单个值,但我不知道如何返回多行。我有一个来自数据库的 ILIST 数据集合。

I can return a single value in my webservice, but I can't figure out how to return multiple rows. I have an ILIST collection of the data from my database.

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

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

发布评论

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

评论(3

人疚 2024-08-19 10:45:01

如果您的 Web 服务的方法返回对象数组,那就可以了。
因此,基本上您只需将该 IList 转换为数组,然后根据 IList 中的对象类型,用要返回的数据填充一些标准对象。

If the method of your web service returns arrays of objects, that should do the trick.
So basically you just have to convert that IList to an array and, depending on what type of objects you have in the IList, fill some standard objects with the data to be returned.

把回忆走一遍 2024-08-19 10:45:01

创建一个可以保存所有行的类,然后返回该类

Create a class that can hold all the rows, then return that class

手心的海 2024-08-19 10:45:01

假设您希望将多个数据传递到 Web 服务并在表中获取结果记录。
这个例子将帮助你理解。

        function searchbudget() {
        var v1= $("#BEMISCODE").val();
        var v2= $("#From_Year").val();
        var v3= $("#To_Year").val();

        var table = $("#tblschoolinfo");

        var d = [];
        d.push(bemiscode);
        d.push(fromyear);
        d.push(toyear);

        var jsnDta = JSON.stringify({ data: d });

        $.ajax({
            type: "POST",
            url: "wbservices/GetBudgetByYearOrBemiscode.asmx/GetCompleteBudgetByBemiscodeOrYear",
            data: jsnDta,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {

                var rtnData = r.d; //all returned data...
                var respDta = [];
                $.map(rtnData, function (item, index) {
                    var j = [
                        item.status,
                        item.msg,
                    ];
                    respDta.push(j);

                });
                $.each(respDta, function (key, value) {
                    var status = value[0];
                    var msg = value[1];

                    if (status == true) {

                        table.html(msg);

                    } else {

                        var eMsg = '<div style="color:white;background:#FF4040" ><i style="margin-left:5px" class="fa fa-exclamation-triangle"></i>"' + msg + '"</div>';
                        table.html(eMsg);

                    }

                }); //1st out loop ends here...


            },
            error: function (jqXHR, textStatus, errorThrown) {
                //  $("#responseMovDetails").html(jqXHR + textStatus + errorThrown);
                alert("error while loading Records of Requests" + jqXHR + textStatus + errorThrown);

            }

        });
    }

Assuming u want multiple data to pass to web service and get resultant records in ur table.
this example will help u to understand.

        function searchbudget() {
        var v1= $("#BEMISCODE").val();
        var v2= $("#From_Year").val();
        var v3= $("#To_Year").val();

        var table = $("#tblschoolinfo");

        var d = [];
        d.push(bemiscode);
        d.push(fromyear);
        d.push(toyear);

        var jsnDta = JSON.stringify({ data: d });

        $.ajax({
            type: "POST",
            url: "wbservices/GetBudgetByYearOrBemiscode.asmx/GetCompleteBudgetByBemiscodeOrYear",
            data: jsnDta,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {

                var rtnData = r.d; //all returned data...
                var respDta = [];
                $.map(rtnData, function (item, index) {
                    var j = [
                        item.status,
                        item.msg,
                    ];
                    respDta.push(j);

                });
                $.each(respDta, function (key, value) {
                    var status = value[0];
                    var msg = value[1];

                    if (status == true) {

                        table.html(msg);

                    } else {

                        var eMsg = '<div style="color:white;background:#FF4040" ><i style="margin-left:5px" class="fa fa-exclamation-triangle"></i>"' + msg + '"</div>';
                        table.html(eMsg);

                    }

                }); //1st out loop ends here...


            },
            error: function (jqXHR, textStatus, errorThrown) {
                //  $("#responseMovDetails").html(jqXHR + textStatus + errorThrown);
                alert("error while loading Records of Requests" + jqXHR + textStatus + errorThrown);

            }

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