Database is not getting updated

Database is not getting updated

siva88siva88 Posts: 17Questions: 3Answers: 0
edited February 2017 in Free community support

Hi,

I was working with datatables. The datatables got loaded successfully after getting help in the forum. I am now trying to add,edit and delete records. When I try to do that, the UI is showing the changes accordingly but the database is not getting updated.

I normally different web service calls in .net - One to get the details, another to insert/update and another to delete. Not sure how this works in Datatables/Editor.

I am new to this and I dont see many examples with server side code in .net (aspx). Most of them are with PHP / .net MVC. Please help me out with this. Please find below the code i have. I also tried to add separate web services for create/edit/remove in ajax but still not able to figure this out. Am not sure how to pass parameter to the web service calls.

Thanks!

HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xxx.cs" Inherits="xxx" %>

<!DOCTYPE html>

<html>
<head runat="server">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- end required meta tags -->

<title>test</title>



<link href="../DataTables/Bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet" type="text/css" /><!-- Do not edit -->
<link href="../DataTables/Bootstrap-3.3.7/css/bootstrap-theme.css" rel="stylesheet" type="text/css" /><!-- Define theme changes here. -->
<link href="../DataTables/DataTables-1.10.13/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Buttons-1.2.4/css/buttons.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Select-1.2.0/css/select.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../DataTables/Editor-1.6.1/css/editor.bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../Styles/test.css" rel="stylesheet" type="text/css" />



<script src="../DataTables/datatables.min.js" type="text/javascript"></script>
<script src="../Scripts/test.js" type="text/javascript"></script>
<!-- End JavaScript Includes -->

</head>
<body>

test

col1 col2 col3 col4 col5

</body>

</html>

Javascript:
(function () {

var editor;


$(document).ready(function () {


    editor = new $.fn.dataTable.Editor({
        ajax: {
        url: "URL to web service",
        contentType: "application/json; charset=utf-8",
        dataType: "json" },
        table: "#Grid-01",
 idSrc: "Id",
        fields: [

        {
        "label": "col 1",
        "name": "col1"
    },
        {
            "label": "col 2",
            "name": "col2"
        },
        {
            "label": "col 3",
            "name": "col3"
        },
        {
            "label": "col 4",
            "name": "col4"
        },
        {
            "label": "col 5",
            "name": "col5"
        }

    ],
    formOptions: {
        inline: {
            onBlur: 'submit'             }
    }
});

$('#Grid-01').DataTable({
    dom: "Bfrtip",
    order: [[1, 'asc']],
    ajax: {
        url: "URL to web service",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        dataSrc: function (json) {
            return JSON.parse(json.d);
    }
    },
    columns: [

{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false

}

                    { "data": "col1" },
                    { "data": " col2" },
                    { "data": " col3" },
                    { "data": " col4" },
                    { "data": " col5" }
        ],
 select: {
        style: 'os',
        selector: 'td:first-child'
     },
     buttons: [
        { extend: "create", editor: editor },
        { extend: "edit", editor: editor },
        { extend: "remove", editor: editor }
        ]       
        });



$('#Grid-01').on('click', 'tbody td:not(:first-child)', function (e) {
    editor.inline(this);
});

});

} ());

DB Web Service

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetdataFunction()
{
string Get = string.Empty;
try
{
using (var db = new DBLookupEntities(Globals.Instance.getdbconnstring()))
{
var me = (from m in db.table1
join d in db.table2 on m.table1id equals d.table2id
select new {

                      id= m.id

col1 = m.col1,
col2= m.col2,
col3= m.col3,
col4= m.col4,
col5= d.col5

                  }).ToList();

        if (me != null)

            Get = JsonConvert.SerializeObject(me);
    }
}
catch (Exception ex)
{
    var error = ex.ToString();

}
return Get;

}

Output of DB web service(value in variable):

{"d":"[{\"col1\":\"12345\",\"col2\":\"123\",\"col3\":\"123\",\"col4\":\"100\",\"col5\":\"test_1]"}

I think I am missing the web services for insert/update/delete but so far all the examples i have seen are in php and don't have explicit call for webservice for the update/delete operations.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    Answer ✓

    so far all the examples i have seen are in php

    You have already been pointed to the .NET libraries manual and the examples
    in the Editor .NET package which contains all of the .NET examples on the site, not limited to php.
    I don't know what else you could need.

This discussion has been closed.