C#调用Oracle数据库的存储过程填充Dataset

一数据表:
student(
studentid varchar2
   studentname varchar2
)
数据:
 studentid              studentname
  001                       001
 002       002
 002       003

第2步建包:
CREATE OR REPLACE PACKAGE PKG_SELECT_STUDENT
AS
   TYPE T_CURSOR IS REF CURSOR;
   PROCEDURE Getusername  
   (
      us_id IN Varchar2,
      cur_name OUT T_CURSOR
   );

第3步建包体:
CREATE OR REPLACE   PACKAGE BODY PKG_SELECT_STUDENT
AS
PROCEDURE Getusername
(
us_id IN varchar2,
cur_name OUT T_CURSOR
   )
   IS
   BEGIN
      OPEN cur_name FOR
      SELECT   *   FROM student WHERE   studentid=us_id;
   END Getusername;
   END PKG_select_student;

  
第4步我的webform.cs文件:

在文本框输入ID,点击按钮查询,有多条数据填充显示在gatagrid里面
private void Button3_Click(object sender, System.EventArgs e)
{
string usid=this.TextBox1.Text.Trim();
Selectop st=new Selectop();
this.DataGrid1.DataSource=st.GetSelectAll(usid);
this.DataGrid1.DataBind();
}

public DataSet GetSelectAll(string usid)
{
OracleConnection con = DBoracle.CreateConnection();
OracleCommand command = new OracleCommand();
DataSet ds = new DataSet();
try
{  

command.Connection=con;
command.CommandText="PKG_select_student.Getusername";
command.CommandType=CommandType.StoredProcedure;
command.Parameters.Add("us_id",OracleType.VarChar,10).Value=usid;
command.Parameters.Add("cur_name",OracleType.Cursor);
command.Parameters["cur_name"].Direction = ParameterDirection.Output;
OracleDataAdapter adapter = new OracleDataAdapter(command);
con.Open();
//command.ExecuteNonQuery();
//adapter.SelectCommand=command;
adapter.Fill(ds);
}
catch(System.Exception ex)
{
throw ex;
}
finally
{
con.Close();
command.Dispose();
//adapter.Dispose();
}
return ds;
}
posted @ 2010-07-27 10:36  你妹的sb  阅读(859)  评论(0编辑  收藏  举报
百度一下