Dataset data is bound to output data through Web Services

Source: Internet
Author: User

1. Web Service Code

   1:  using System;
   2:  using System.Data;
   3:  using System.Data.SqlClient;
   4:  using System.Diagnostics;
   5:  using System.Web.Services;
   6:  using System.Web.Configuration;
   7:   
   8:  /// <summary>
   9:  /// Summary description for CategoriesService
  10:  /// </summary>
  11:  [WebService(Namespace = "http://tempuri.org/")]
  12:  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  13:  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  14:  // [System.Web.Script.Services.ScriptService]
  15:  public class CategoriesService : System.Web.Services.WebService {
  16:   
  17:      public CategoriesService () {
  18:   
  19:          //Uncomment the following line if using designed components 
  20:          //InitializeComponent(); 
  21:      }
  22:   
  23:      [WebMethod]
  24:      public DataSet GetCategoriesAsDataset()
  25:      {
  26:          try
  27:          {
  28:              using (SqlConnection conn = new SqlConnection())
  29:              {
  30:                  string connectionString = WebConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
  31:                  conn.ConnectionString = connectionString;
  32:                  SqlCommand command = new SqlCommand("select * from Production.ProductCategory", conn);
  33:                  command.CommandType = CommandType.Text;
  34:                  SqlDataAdapter adapter = new SqlDataAdapter(command);
  35:                  DataSet categories = new DataSet("Categories");
  36:                  adapter.Fill(categories);
  37:                  return categories;
  38:              }
  39:          }
  40:          catch(Exception ex)
  41:          {
  42:              EventLog.WriteEntry("Application", ex.Message);
  43:              throw ex;
  44:          }
  45:          
  46:      }
  47:      
  48:  }
  49:   

2. code structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.