此方法完成了简单WebService 的简单调用封装,实现了简单Webservice简单调用的统一操作,避免了每增加一个操作都必须增加一个接口方法 的囧状!
/// <summary> /// 封装同一的接口调用方法 /// </summary> /// <param name="_strSql">传入的简单sql</param> /// <param name="_strConnNmae">连接数据库字符串</param> /// <returns>返回的dataset</returns> [WebMethod] public DataSet GeneralDataSet(string _strSql, string _strConnNmae) { DataSet dsResult = null; //连接HIS数据库串 ConnectionStringSettings css = new ConnectionStringSettings(); css = ConfigurationManager.ConnectionStrings[_strConnNmae]; using (OleDbConnection conn = new OleDbConnection(css.ConnectionString)) { conn.Open(); OleDbCommand cmd = conn.CreateCommand(); using (OleDbDataAdapter ada = new OleDbDataAdapter()) { try { cmdHIS.CommandText = _strSql; ada.SelectCommand = cmdHIS; ada.Fill(dsResult); } catch (Exception ex) { } } } return dsResult; }
<configuration> <appSettings> <add key="EmrSoapRole" value="http://www.goodwill.com/EMR"/> </appSettings> <connectionStrings> <add name="HISConnectionString" connectionString="Data Source=DLFY;Persist Security Info=True;Password=medrec;User ID=medrec" providerName="System.Data.OracleClient"/>
//调用示例 DataSet ds = GeneralDataSet("select * from emp","HisConnectionString");
以上所述就是本文的全部内容了,希望大家能够喜欢。