我正在尝试创建更新linq查询&我使用jQuery生成表,所以在更新后如何保存对表中数据的更改?
[WebMethod]
public static string updateselect_data(int ServiceID, string frequency, string Freq_Du, string Freq_Mil)
{
string query_update = "";
try
{
Track_Data track = new Track_Data();
DataTable dt = new DataTable();
var update =
from p in track.Serv
where p.ServiceID == ServiceID
select p;
foreach (var q_update in update)
{
q_update.frequency= frequency;
q_update.Freq_Du= Freq_Du;
q_update.Freq_Mil= Freq_Mil;
}
HttpContext.Current.Session["SID"] = ServiceID;
HttpContext.Current.Session["frequency"] = frequency;
HttpContext.Current.Session["Freq_Du"] = Freq_Du;
HttpContext.Current.Session["Freq_Mil"] = Freq_Mil;
try
{
track.SaveChanges();
}
catch (Exception e)
{
throw new Exception();
}
update.ToList().ForEach(row => dt.LoadDataRow(new object[] {
row.ServiceID, row.Frequency, row.Freq_Du, row.Freq_Mil }, false));
query_update = DataSetToJSON(dt);
return query_update;
}
catch
{
throw new Exception();
}
JQUERY CODE
<script type="text/javascript">
debugger;
$(function () {
$('[ID*=btn_update]').on('click', function () {
var ServiceID = '<%=Session["SID"]%>';
var frequency='<%=Session["frequency"]%>';
var Freq_Du = '<%=Session["Freq_Dur"]%>';
var Freq_Mil = '<%=Session["Freq_Mil"]%>';
debugger;
var obj = {};
obj.ServiceID = ServiceID;
obj.frequency = frequency;
obj.Freq_Dur= Freq_Du;
obj.Freq_Mil = Freq_Mil;
updatedata(obj);
});
});
function updatedata(obj){
$.ajax({
type: "POST",
url: "Maintenance.aspx/updateselect_data",
contentType: "application/json;charset=utf-8",
data:"{'SID:'"+ obj.ServiceID+"','frequency:'"+obj.frequency+"','Freq_Du:'"+obj.Freq_Du+"','Freq_Mil:'"+obj.Freq_Mil+"'}",
dataType: "json",
success:function(result)
{
debugger;
var up = JSON.parse(result.d).response;
}
});
}
</script>
我创建表throgh jquery现在我首先想要更新并且想要在我上面执行代码时检查控制台这个显示错误s
在JSON中传递的无效对象
答案 0 :(得分:0)
您已声明以下内容,但未指定任何值。
int ServiceID ;
string Service_frequency;
string Next_Service;
例如;
int ServiceID = 1 ;
string Service_frequency = "Weekly";
string Next_Service = "Tomorrow";