This code for load data member
public ActionResult LoadData()
{
string query = "SELECT NAME, DATELASTUSE, CREATE_ID FROM MEMBER";
using (OdbcConnection c = new OdbcConnection(Connection.Conn()))
{
OdbcCommand cmd = new OdbcCommand(query, c);
c.Open();
OdbcDataReader dr = cmd.ExecuteReader();
var dataTable = new DataTable();
dataTable.Load(dr);
return **json for ajax** ;
}
}
$(document).ready(function () {
var oTable = $("#PassTable").DataTable({
"ajax": {
"url": "/Home/LoadData",
"type": "GET",
"datatype": "json"
},
"columns": [
{ "data": "NAME", "autowidth": true },
{ "data": "DATELASTUSE", "autowidth": true },
{ "data": "CREATED_ID", "autowidth": true },
],
"language": {
"emptytable": "No data found, Please click on <b>Add New</b> button"
}
});
});
<table id="PassTable" class="table table-border table-hover" style="background-color:white;" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Date</th>
<th>Created_By</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
LoadData is From HomeController
I don't know how to return datareader to json.
I don't understand the flow just try in error use -> return Json(new { data = dataTable }, JsonRequestBehavior.AllowGet);
but Gv me error.
Please Help.
Thx.