Web服务返回Dataset对象

   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:   

转载于:https://www.cnblogs.com/apiaceae/archive/2009/04/20/1439611.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值