title: about a web service retrieving data from MySQL database
body: <p>I am trying to create a web service that can get data from MYSQL database but I have a problem </p>
  
  <p>the web form code </p>
  
  <pre><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();
          }
      }
  }
  </code></pre>
  
  <p>and the web service code </p>
  
  <pre><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;
                          }
                      }
                  }
              }
  </code></pre>
  
  <p>I just follow the steps from this tutorial: </p>
  
  <p><a href="http://www.aspsnippets.com/Articles/Retrieve-Get-data-from-Database-using-Web-Service-in-ASPNet-using-C-and-VBNet.aspx" rel="nofollow">http://www.aspsnippets.com/Articles/Retrieve-Get-data-from-Database-using-Web-Service-in-ASPNet-using-C-and-VBNet.aspx</a> </p>
  
  <p>or if you have any useful reference about getting data from SQL database using  web service in ASP.NET and C# please help me </p>
  
  <p>thanks in advance </p>