public class theatresController : ApiController
{
[HttpGet]
public static DataTable GetAlltheatredet()
{
try
{
string connString = "Server=localhost;database=mytable;uid=root;";
string query = "SELECT TheatreName FROM `mytable`.`theatredetails`";
MySqlDataAdapter ma = new MySqlDataAdapter(query, connString);
DataSet DS = new DataSet();
ma.Fill(DS);
return DS.Tables[0];
}
catch (MySqlException e)
{
throw new Exception(e.Message);
}
}
I am fetching my table data from DB by using datatable. How can I convert all these datas to json
I tried by using this in an html file
$(document).ready(function ()
{
$("#Theaterdet").click(function ()
{
alert("in document submit");
$.ajax({
type: "GET",
url: "/api/theatres/",
dataType: 'json',
success: function (data)
{
},
error: function ()
{
alert("Error while invoking the Web API");
}
});
});
});
But I got error... How can I implement this functionality?