存储更新LINQ查询并传递给json [英] Store update LINQ query and pass to json

查看:68
本文介绍了存储更新LINQ查询并传递给json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建更新linq查询&我使用jQuery生成表,所以更新后如何保存对表中数据的更改?

I am trying to create an update linq query & I generate table using jQuery so after update how do I save changes to data in the table?

JQUERY

现在我从表中获取ServiceID,并尝试基于ServiceID更新记录

now i get ServiceID from table and i try to update record on the bases of ServiceID

我试试这个

                $(function () {
                    $('#services_schdulue').on('click', 'tr', function () {
                        debugger;
                        var row = $(this);
                        var ServiceID = row.find('td')[0].firstChild.data;
                        var s = {};
                        s.ServiceID = ServiceID;


                    $('[ID*=btn_update]').on('click', function () {
                        debugger;
                        var ServiceID = s.ServiceID;
                         var frequency = $('#txt_repeat').val();
                        var Freq_Du = $('#dura_values').val();
                        var Freq_Mil= $('#text_mil').val();

                        debugger;

                        var obj = {};
                        obj.ServiceID = ServiceID;
                        obj.frequency = frequency;
                        obj.Freq_Du = Freq_Du;
                        obj.Freq_Mi= Freq_Mil;
                        updatedata(obj);

                    });
                });
             }
         alert("12-1");
                function updatedata(obj) {
                    $.ajax({
                        type: "POST",
                        url: "Maintenance.aspx/updateselect_data",
                        contentType: "application/json;charset=utf-8",
                        data: "{'ServiceID':'" + obj.ServiceID + "','frequency':'" + obj.frequency + "','Freq_Du':'" + obj.Freq_Du + "','Freq_Mil':'" + obj.Freq_Mil + "'}",
                        dataType: "json",
                        async: true,
                        cache: false,
                    success:function(result)
                    {
                        alert("15-1");
                        debugger;
             var up = JSON.parse(result.d).response;
     $("#txt_repeat" + obj.frequency).html(obj.frequency);
            $("#dura_values" + obj.Freq_Duration).html(obj.Freq_Duration);
            $("#text_mil" + obj.Freq_Mileage).html(obj.Freq_Mileage);

            $("#text_mil" + obj.frequency + obj.Freq_Duration + obj.Freq_Mileage).html(obj.frequency + obj.Freq_Duration + obj.Freq_Mileage);
                    },
                    error: function (error) {
                        var r = error.responseText;
                        var errorMessage = r.Message;
                         alert(errorMessage);
                        alert(r);
                        alert("error")
                    }

                });
                }

像这样的数据库表中的数据

data in database table like this

 Service ID frequency Freq_Du Freq_Mil
    1           2         month          1200

我在这样的页面中显示数据

and i display data in page like this

 Service ID    Info
    1           2 month 1200

现在,当我更新此记录时,更改将反映在数据库表中,而不反映在我在页面中显示的表中

now when i update this record changes reflect in database table but not reflect in table which i display in page

我像这样在1个单元格中串联数据

i concatenate data in 1 cell like this

 var example = $("#services_schdulue").DataTable({
                        "dom": 'Blfrtip',
                        "columns":[
                            {
                                "title": "Service ID",
                                "data": "Service ID"
                            },{
                                "title": "frequency",
                                "data": "frequency",
                                "visible": false
                            }, {
                                "title": "Freq_Du",
                                "data": "Freq_Du",
                                "visible": false
                            },{
                                "title": "Freq_Mil",
                                "data": "Freq_Mil",
                                "render": function(data, type, row){
                 return row.frequency + row.Freq_Du+ row.Freq_Mil
                                }
                            },

推荐答案

您的参数不匹配. 在您的网络方法中,方法签名需要

Your parameters don't match. In your webmethod the method signature requires

 int ServiceID, string frequency, string Freq_Du, and string Freq_Mil

在您的ajax帖子中是

In your ajax post it's

data: "{'SID':'" + obj.ServiceID + "','frequency':'" + obj.frequency + "','Freq_Du':'" + obj.Freq_Du + "','Freq_Mil':'" + obj.Freq_Mil + "'}".

data: "{...}"会简单地将字符串传递给您的updateselect_data(int, string, string, string).不要期望您的计算机太多.没有显式指令,它不知道如何将字符串转换为int.

The data: "{...}" will simply pass a string to your updateselect_data(int, string, string, string). Don't expect too much of your computer. It doesn't know how to convert a string to an int without explicitly instruction.

这篇关于存储更新LINQ查询并传递给json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆