C#调用oracle存储过程(返回数据集)
2012-05-21 13:05
441 查看
表:STUDENT(NAME,SEX,SCORE)
ORACLE包和存储过程:首先在ORACLE建立PACKAGE和PACKAGE BODY,将在这里面定义函数和存储过程返回结果集。
1,建立PACKAGE:
CREATE OR REPLACE PACKAGE SENYI.PACK_STU
IS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE PRO_STUDENT(RE_CURSOR OUT T_CURSOR);
END;
/
说明:其实PACKAGE只是个声明罢了。我们在这里定义了一个存储过程返回结集。
2,建立PACKAGE BODY:
CREATE OR REPLACE PACKAGE BODY SENYI.PACK_STU
IS
PROCEDURE PRO_STUDENT(RE_CURSOR OUT T_CURSOR)
IS
V_CURSOR T_CURSOR;
BEGIN
OPEN V_CURSOR FOR
SELECT * FROM SENYI.STUDENT;
RE_CURSOR:=V_CURSOR;
END;
END;
/
说明:这里建立PACKAGE BODY是具体的说明和使用,将采用什么方式实现。。
------------------------------
c# 部分:
string str="server=ORCL;user id=senyi;password=orcl";
OracleConnection con = new OracleConnection(str);
con.Open();
OracleParameter[] para = new OracleParameter[]{
new OracleParameter("RE_CURSOR", OracleType.Cursor)
};
para[0].Direction = System.Data.ParameterDirection.Output;
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SENYI.PACK_STU.PRO_STUDENT";//注意此处存储过程的调用: 包+存储过程名
foreach (OracleParameter pa in para)
{
cmd.Parameters.Add(pa);
}
OracleDataAdapter da = new OracleDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
DataTable dt = ds.Tables[0];
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
ORACLE包和存储过程:首先在ORACLE建立PACKAGE和PACKAGE BODY,将在这里面定义函数和存储过程返回结果集。
1,建立PACKAGE:
CREATE OR REPLACE PACKAGE SENYI.PACK_STU
IS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE PRO_STUDENT(RE_CURSOR OUT T_CURSOR);
END;
/
说明:其实PACKAGE只是个声明罢了。我们在这里定义了一个存储过程返回结集。
2,建立PACKAGE BODY:
CREATE OR REPLACE PACKAGE BODY SENYI.PACK_STU
IS
PROCEDURE PRO_STUDENT(RE_CURSOR OUT T_CURSOR)
IS
V_CURSOR T_CURSOR;
BEGIN
OPEN V_CURSOR FOR
SELECT * FROM SENYI.STUDENT;
RE_CURSOR:=V_CURSOR;
END;
END;
/
说明:这里建立PACKAGE BODY是具体的说明和使用,将采用什么方式实现。。
------------------------------
c# 部分:
string str="server=ORCL;user id=senyi;password=orcl";
OracleConnection con = new OracleConnection(str);
con.Open();
OracleParameter[] para = new OracleParameter[]{
new OracleParameter("RE_CURSOR", OracleType.Cursor)
};
para[0].Direction = System.Data.ParameterDirection.Output;
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SENYI.PACK_STU.PRO_STUDENT";//注意此处存储过程的调用: 包+存储过程名
foreach (OracleParameter pa in para)
{
cmd.Parameters.Add(pa);
}
OracleDataAdapter da = new OracleDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
DataTable dt = ds.Tables[0];
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
相关文章推荐
- 关于c#调用oracle存储过程返回数据集的写法
- c#调用oracle存储过程返回数据集
- 123 c#调用oracle存储过程返回数据集 --通过oracle存储过程返回数据集
- C#调用ORACLE存储过程返回结果集及函数
- Delphi7下用dbExpress调用Oracle存储过程(返回数据集)的一个简单示例和调试过程
- C#调用ORACLE存储过程返回结果集及函数
- delphi调用C# Webservice返回数据集
- C#调用ORACLE存储过程返回结果集及函数
- Delphi7下用dbExpress调用Oracle存储过程(返回数据集)的一个简单示例和调试过程
- C#调用ORACLE存储过程返回结果集
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- 微软企业库调用Oracle存储过程返回(1个或多个)数据集(转载)
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- C#调用ORACLE存储过程返回结果集及函数
- Oracle创建表语句(Create table)语法详解及示例、、 C# 调用Oracle 存储过程返回数据集 实例
- C#调用ORACLE存储过程返回结果集及函数