美文网首页
服务端调用存储过程

服务端调用存储过程

作者: a9b854aded01 | 来源:发表于2017-10-13 11:26 被阅读0次

    返回一个DataSet的例子

    客户端

    DataSet dscode = (DataSet)WebServiceHepler.WebServiceHepler.InvokeWebService(url + "NewGoodSet.asmx", "getGoodsCode", null);
    

    服务端

      [WebMethod]
        public DataSet getGoodsCode()
        {
            return new Service().SelectCommon("BD_ProductCodeTab ", " PC_Code ", "1=1 Group By PC_Code Order By PC_Code");
        }
    
     [WebMethod]
        public DataSet SelectCommon(string strtblName, string strFields, string strWhere)
        {
            DataAccess da = new DataAccess();
            SqlConnection sqlConn = da.GetConnection();//数据库连接
            if (sqlConn.State != ConnectionState.Open) sqlConn.Open();//打开数据库连接
            SqlTransaction sqlTrans = sqlConn.BeginTransaction();//调用事务处理
            DataSet ds = new DataSet();
            try
            {
    
    
                SqlParameter[] commandParameters = new SqlParameter[3];
                commandParameters[0] = new SqlParameter("@tblName", SqlDbType.VarChar, 1000);
                commandParameters[0].Value = strtblName;
                commandParameters[1] = new SqlParameter("@strFields", SqlDbType.VarChar, 4000);
                commandParameters[1].Value = strFields;
                commandParameters[2] = new SqlParameter("@strWhere", SqlDbType.VarChar, 2000);
                commandParameters[2].Value = strWhere;
                ds = da.ExecuteDataset(da.GetConnStr(), CommandType.StoredProcedure, "P_Common_Select", commandParameters);
                //        ds = da.ExecuteDataset(da.GetConnStr(), CommandType.StoredProcedure, "P_Common_Insert_CArdInfor", commandParameters);
                sqlTrans.Commit();//提交事务
                sqlConn.Close();//关闭连接
                return ds;
            }
            catch (Exception ex)
            {
                sqlTrans.Rollback();//回传数据
                sqlConn.Close();//关闭连接
                throw ex;
                //  return 0;//有异常 
            }
        }
    
    

    相关文章

      网友评论

          本文标题:服务端调用存储过程

          本文链接:https://www.haomeiwen.com/subject/fdczyxtx.html