/// <summary> /// [SQL Server] 데이터셋 반환(프로시저) /// </summary> /// <param name="param">첫 번째 인자는 프로시저명, 두 번째부터는 파라미터들</param> /// <returns>데이터셋</returns> public DataSet GetDataSet(params object[] param) { // SQL Server용 DataSet 반환 함수입니다. // 프로시저 전용이므로, ad-hoc 쿼리를 이용하실 수는 없습니다. } /// <summary> /// [SQL Server] 데이터셋 반환(Ad-hoc 쿼리) /// </summary> /// <param name="_strQuery">Ad-hoc 쿼리문</param> /// <returns>데이터셋</returns> public DataSet GetDataSet(string _strQuery) { // SQL Server용 DataSet 반환 함수입니다. // ad-hoc 쿼리 전용이므로, 프로시저도 이용하실 수 있지만 권장하지는 않습니다. } /// <summary> /// [Oracle] 데이터셋 반환(프로시저) /// </summary> /// <param name="_strProcedureName">프로시저명</param> /// <param name="_inputParams">Input 파라미터</param> /// <param name="_outputParams">Output 파라미터</param> /// <returns>데이터셋</returns> public DataSet GetDataSet(string _strProcedureName, Dictionary<object, object> _inputParams, params string[] _outputParams) { // Oracle용 DataSet 반환 함수입니다. // 프로시저 전용이므로, ad-hoc 쿼리를 이용하실 수는 없습니다. } /// <summary> /// [Oracle] 데이터셋 반환(Ad-hoc 쿼리) /// </summary> /// <param name="_strQuery">Ad-hoc 쿼리문</param> /// <returns>데이터셋</returns> public DataSet GetDataSet(string _strQuery) { // Oracle용 DataSet 반환 함수입니다. // ad-hoc 쿼리 전용이므로, 프로시저도 이용하실 수 있지만 권장하지는 않습니다. } /// <summary> /// [SAP] 데이터셋 반환(프로시저) /// </summary> /// <param name="tran">트랜잭션 여부</param> /// <param name="param">첫 번째 인자는 RFC명, 두 번째부터는 파라미터들(입력 파라미터명, 값)</param> /// <returns>데이터셋</returns> public DataSet GetDataSet(bool tran, params object[] param) { // SAP RFC용 DataSet 반환 함수입니다. // 이 함수를 이용하시려면, 다음의 2단계 과정을 거쳐야 합니다. // 1단계) 1단계) web.config에 아래의 형식에 맞는 SAP 연결 문자열을 지정합니다. // ASHOST=127.0.0.1 SYSNR=10 USER=RFC_USER PASSWD=12345 CLIENT=100 LANG=KO CPIC_MAX_CONV=500 // 물론 이 문자열도 Triple-DES로 암호화 되어 있어야 겠지요? // 2단계) 2단계) SAP .NET Connector 어셈블리를 웹 프로젝트에 추가합니다. // sapnco.dll, sapnco_utils.dll // 상기 어셈블리들은 SAP Community Network(http://http://scn.sap.com)에서 다운받으실 수 있습니다. // 로그인 계정은 SAP 파트너회사에 문의하세요. // 32비트용과 64비트용이 따로 있으니, 웹 서버에 맞게 다운 받으셔야 합니다. // 때로는 Microsoft Visual C++ 2010 Redistributable Package(http://www.microsoft.com/en-us/download/details.aspx?id=14632)가 필요할 경우도 있습니다. // 웹 서버에 설치해 주셔야 합니다. // Microsoft Visual C++ 2010 Redistributable Package 도 32비트용과 64비트용이 따로 있으니, 주의하셔서 설치하세요. }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetDataSet.aspx.cs" Inherits="BANANA.Web.Framework.Test.jmson.GetDataSet" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>GetDataSet</title> </head> <body> <form id="form1" runat="server"> <fieldset> <legend>Employees</legend> <asp:GridView ID="GridView1" runat="server" /> </fieldset> <br /><br /> <fieldset> <legend>Customers</legend> <asp:GridView ID="GridView2" runat="server" /> </fieldset> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace BANANA.Web.Framework.Test.jmson { public partial class GetDataSet : BANANA.Web.BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet _ds = base.GetDataSet( "TEST" // 첫 번째 파라미터는 프로시저 명을 입력해 주세요. , "co" // 두번째 부터는 프로시저에 전달할 변수를 입력하시면 됩니다. ); GridView1.DataSource = _ds.Tables[0]; GridView1.DataBind(); GridView2.DataSource = _ds.Tables[1]; GridView2.DataBind(); } } } }
CREATE PROC [dbo].[TEST] ( @LastName NVARCHAR(20) ) AS BEGIN SELECT EmployeeID, LastName, FirstName, Title, TitleOfCourtesy, BirthDate, HireDate, Address, City, Region, PostalCode, Country, HomePhone, Extension, Photo, ReportsTo, PhotoPath FROM dbo.Employees WHERE LastName LIKE '%' + @LastName + '%' SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM dbo.Customers WHERE ContactName LIKE '%' + @LastName + '%' END
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace BANANA.Web.Framework.Test.jmson { public partial class GetDataSet : BANANA.Web.BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string _strLastName = "co"; string _strQuery = "SELECT EmployeeID, LastName, FirstName, Title, TitleOfCourtesy"; _strQuery += ", BirthDate, HireDate, Address, City, Region, PostalCode, Country, HomePhone"; _strQuery += ", Extension, Photo, ReportsTo, PhotoPath "; _strQuery += "FROM dbo.Employees "; _strQuery += "WHERE LastName LIKE '%" + _strLastName + "%'; "; _strQuery += "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City"; _strQuery += ", Region, PostalCode, Country, Phone, Fax "; _strQuery += "FROM dbo.Customers "; _strQuery += "WHERE ContactName LIKE '%" + _strLastName + "%';"; DataSet _ds = base.GetDataSet(_strQuery); // ad-hoc 쿼리를 하나의 string에 담아서 전달하면 됩니다. GridView1.DataSource = _ds.Tables[0]; GridView1.DataBind(); GridView2.DataSource = _ds.Tables[1]; GridView2.DataBind(); } } } }
-- Package Spec 정의 CREATE OR REPLACE PACKAGE PKG_EMPLOYEES AS TYPE T_CURSOR IS REF CURSOR; PROCEDURE WSP_EMPLOYEES_R1 ( I_LASTNAME IN VARCHAR2 , I_EMPLOYEEID IN NUMBER , O_EMPLOYEES OUT T_CURSOR , O_CUSTOMERS OUT T_CURSOR ); END PKG_EMPLOYEES;
-- Package Body 정의 CREATE OR REPLACE PACKAGE BODY PKG_EMPLOYEES AS PROCEDURE WSP_EMPLOYEES_R1 ( I_LASTNAME IN VARCHAR2 , I_EMPLOYEEID IN NUMBER , O_EMPLOYEES OUT T_CURSOR , O_CUSTOMERS OUT T_CURSOR ) IS BEGIN -- EMPLOYEES OPEN O_EMPLOYEES FOR SELECT * FROM EMPLOYEES WHERE LASTNAME LIKE '%'||I_LASTNAME||'%' AND EMPLOYEEID > I_EMPLOYEEID; -- CUSTOMERS OPEN O_CUSTOMERS FOR SELECT * FROM CUSTOMERS; END WSP_EMPLOYEES_R1; END PKG_EMPLOYEES;
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace BANANA.Web.Framework.Test.jmson { public partial class GetDataSet : BANANA.Web.BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { // Input 파라미터를 순서에 맞게 Dictionary 개체에 추가합니다. Dictionary<object, object> _dic = new Dictionary<object, object>(); _dic.Add("I_LASTNAME", "King"); _dic.Add("I_EMPLOYEEID", 1); DataSet _ds = base.GetDataSet( "PKG_EMPLOYEES.WSP_Employees_R1" , _dic , "O_EMPLOYEES" // Output 커서명들을 하나씩 입력하면 됩니다. , "O_CUSTOMERS" // 상동 ); GridView1.DataSource = _ds.Tables[0]; GridView1.DataBind(); GridView2.DataSource = _ds.Tables[1]; GridView2.DataBind(); } catch (Exception err) { MessageBox.Show(err.Message , "데이터베이스 오류" , MessageBox.MessageBoxType.Alert , MessageBox.MessageBoxIcon.Error ); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace BANANA.Web.Framework.Test.jmson { public partial class GetDataSet : BANANA.Web.BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { DataSet _ds = base.GetDataSet( "SELECT * FROM EMPLOYEES; SELECT * FROM CUSTOMERS;" // ad-hoc 쿼리를 하나의 string에 담아서 전달하면 됩니다. ); GridView1.DataSource = _ds.Tables[0]; GridView1.DataBind(); GridView2.DataSource = _ds.Tables[1]; GridView2.DataBind(); } catch (Exception err) { MessageBox.Show(err.Message , "데이터베이스 오류" , MessageBox.MessageBoxType.Alert , MessageBox.MessageBoxIcon.Error ); } } } } }