I am trying to create a web service that can get data from MYSQL database but I have a problem
the web form code
namespace John
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
localhost.Service1 service = new localhost.Service1();
GridView1.DataSource = service.Get();
GridView1.DataBind();
}
}
}
and the web service code
public DataTable Get()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM nursery1"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
dt.TableName = "nursery1";
sda.Fill(dt);
return dt;
}
}
}
}
I just follow the steps from this tutorial:
or if you have any useful reference about getting data from SQL database using web service in ASP.NET and C# please help me
thanks in advance
Aucun commentaire:
Enregistrer un commentaire