I'm new to C# and javacript. I'm doing my first program on Visual Studio and I have one problem to retrieve data from a SQL Server database.
I want to retrieve data from SQL Server and convert it to Json by using an ajax method. But when I start my web page I can see only the table empty, so I think I have not a good method to connect to my data base.
Here is the code for my WebMethod used to retrieve data and convert to Json:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using Newtonsoft.Json;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string LoadData()
{
string strcon = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection con = new SqlConnection(strcon);
SqlCommand cmd = new SqlCommand("select * from kit", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return JsonConvert.SerializeObject(ds.Tables[0]);
}
Please I need your Help I have done several days on this program. Thanks for all your help.