首页 ┆ 网站地图 ┆ 在线留言 ┆ 游戏资讯 ┆ 资源下载 ┆ 端午节祝福 ┆ 迅雷在线影视 ┆淘宝手机在线充值 ┆淘宝游戏点卡充值 
设为首页
加入收藏
联系我们
高级搜索
您当前的位置: 主页>NET专区>SERVICES>如何使用WebServices调用存储过程代码实例
如何使用WebServices调用存储过程代码实例
来源: 发布时间:2008-04-09 发布人: 浏览: 人次   字体: [ ]  

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
using System.Web.Services.Protocols;

namespace SFXTWebService
{
 /// <summary>
 /// Service1 的摘要说明。
 /// </summary>
 public class Service1 : System.Web.Services.WebService
 {
  public Service1()
  {
   //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
   InitializeComponent();
  }
  #region 组件设计器生成的代码  
  //Web 服务设计器所必需的
  private IContainer components = null;
    
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {  }
  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if(disposing && components != null)
   {
    components.Dispose();
   }
   base.Dispose(disposing);  
  }
  
  #endregion

  // WEB 服务示例
  // HelloWorld() 示例服务返回字符串 Hello World
  // 若要生成,请取消注释下列行,然后保存并生成项目
  // 若要测试此 Web 服务,请按 F5 键
  #region SFQD
  [WebMethod]
  public DataSet GetProcedureSFQD(string strp_lsh,out string strp_zt)
  {
   string strDBConnection = "";
   strDBConnection = System.Configuration.ConfigurationSettings.AppSettings["ConnDBString"];
   OleDbConnection oleConn = new OleDbConnection(strDBConnection);
   oleConn.Open();
   OleDbCommand oleComm = new OleDbCommand("SFXT.SP_SF_BANK_SFQD",oleConn);//调用存储过程的方法
   oleComm.CommandType = CommandType.StoredProcedure;//存储过程名称
   try
   {    
    //in参数
    oleComm.Parameters.Add(new OleDbParameter("p_lsh",OleDbType.VarChar,50)).Value = strp_lsh;

    //out参数
    oleComm.Parameters.Add(new OleDbParameter("p_zt",OleDbType.VarChar,50));
    oleComm.Parameters["p_zt"].Direction = ParameterDirection.Output;

    oleComm.ExecuteNonQuery();//执行存储过程
    
    //赋值
    strp_zt = oleComm.Parameters["p_zt"].Value.ToString();

    string str1 = oleComm.Parameters["p_zt"].Value.ToString();
    DataSet ds = new DataSet();

    DataTable table1 = new DataTable();
    ds.Tables.Add(table1);
    ds.Tables[0].Columns.Add("p_zt");

    DataRow dr = ds.Tables[0].NewRow();
    dr[0] = str1;

    ds.Tables[0].Rows.Add(dr);
    return ds;
   }
   catch(Exception)
   {
    strp_zt = "";
    return null;
   }
   finally
   {
    oleConn.Close();
    oleConn.Dispose();
   }  }
  #endregion

  #region YSF
  [WebMethod]
  public DataSet GetProcedureYSF(string strp_lsh,string strp_YKZJE,string strp_CSDWDM,string strp_YKSH,out string strp_zt,out string strp_errordesc)
  {   
   string strDBConnection = "";
   strDBConnection = System.Configuration.ConfigurationSettings.AppSettings["ConnDBString"];
   OleDbConnection oleConn = new OleDbConnection(strDBConnection);
   oleConn.Open();
   OleDbCommand oleComm = new OleDbCommand("SFXT.SP_SF_BANK_YSF",oleConn);//调用存储过程的方法
   oleComm.CommandType = CommandType.StoredProcedure;//存储过程名称
   try
   {    //in参数
    oleComm.Parameters.Add(new OleDbParameter("p_lsh",OleDbType.VarChar,50)).Value = strp_lsh;
    oleComm.Parameters.Add(new OleDbParameter("p_YKZJE",OleDbType.VarChar,50)).Value = strp_YKZJE;
    oleComm.Parameters.Add(new OleDbParameter("p_CSDWDM",OleDbType.VarChar,50)).Value = strp_CSDWDM;
    oleComm.Parameters.Add(new OleDbParameter("p_YKSH",OleDbType.VarChar,50)).Value = strp_YKSH;

    //out参数
    oleComm.Parameters.Add(new OleDbParameter("p_zt",OleDbType.VarChar,50));
    oleComm.Parameters["p_zt"].Direction = ParameterDirection.Output;
    oleComm.Parameters.Add(new OleDbParameter("p_errordesc",OleDbType.VarChar,50));
    oleComm.Parameters["p_errordesc"].Direction = ParameterDirection.Output;

    oleComm.ExecuteNonQuery();//执行存储过程
    //赋值
    strp_zt = oleComm.Parameters["p_zt"].Value.ToString();
    strp_errordesc = oleComm.Parameters["p_errordesc"].Value.ToString();

    string str1 = oleComm.Parameters["p_zt"].Value.ToString();
    string str2 = oleComm.Parameters["p_errordesc"].Value.ToString();
    DataSet ds = new DataSet();
    DataTable table1 = new DataTable();
    ds.Tables.Add(table1);
    ds.Tables[0].Columns.Add("p_zt");
    ds.Tables[0].Columns.Add("p_errordesc");

    DataRow dr = ds.Tables[0].NewRow();
    dr[0] = str1;
    dr[1] = str2;
    ds.Tables[0].Rows.Add(dr);
    return ds;
   }
   catch(Exception)
   {
    strp_zt = "";
    strp_errordesc = "";
    return null;
   }
   finally
   {
    oleConn.Close();
    oleConn.Dispose();
   }
  }  #endregion
 }
}


相 关 文 章   发布商链接
·如何实现不用编写客户端也能调试WebS...
·webservice在远程不能被调用解决方案
·取消一个正在进行中的Web Service
·哪些情况可以使用Web service,哪些...
·如何实现在asp.net中实现WebServices...
·探讨Web Service什么时候该用,什么...
·通过Web Services上传和下载文件的实...
·如何创建和使用Web服务
·小解ASP.NET AJAX中的异步Web Servic...
 §最新评论:(评论内容只代表网友观点,与本站立场无关!)
网名: 验证码:  【所有评论】【↑返回顶部
评 分: 12 345
评论内容:(不能超过500字,请自觉遵守互联网相关政策法规。[按 Ctrl+Enter 可直接提交]
注意:请勿在本站发布政治话题、色情及违反法律的内容。
IT知道网 声明:刊登此文章是为了传递更多信息,文章内容仅供参考,转载请注明出处。
推 荐 文 章
·webservice在远程不能被调用...
·如何实现不用编写客户端也能...
·小解ASP.NET AJAX中的异步Web...
热 门 文 章
·如何实现不用编写客户端也能...
·通过Web Services上传和下载...
·小解ASP.NET AJAX中的异步Web...
·webservice在远程不能被调用...
·哪些情况可以使用Web service...
·如何实现在asp.net中实现WebS...
·如何创建和使用Web服务
·取消一个正在进行中的Web Ser...
·探讨Web Service什么时候该用...
网站首页 - 关于本站 - 加入收藏 - 网站地图 - 友情连接 - 在线留言 - 联系我们 - 返回顶部
Copyright © 2007 IT知道网.[冀ICP备07026896号]. All Rights Reserved .