缤纷多彩的植物信息世界

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
   1:  using System;
   2:  using System.Web.Configuration;
   3:  using System.Web.Services;
   4:  using System.Data;
   5:  using System.Data.SqlClient;
   6:  using System.Diagnostics;
   7:   
   8:  /// <summary>
   9:  /// Summary description for CategoryService
  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 CategoryService : System.Web.Services.WebService {
  16:   
  17:      public CategoryService () {
  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:   
posted on 2009-04-20 12:52  虎克  阅读(397)  评论(0编辑  收藏  举报