c#中利用pl/sql匿名块和游标获取多个结果集

1.创建测试表并插入数据:

 

SQL> create table TESTTAB1

  2  (

  3    NAME1 VARCHAR2(10)

  4  );

 

表被创建

 

SQL>

SQL> create table testtab2

  2  (

  3    name2 varchar2(10)

  4  )

  5  ;

 

表被创建

 

SQL> insert into testtab1 values('testtab1');

 

1 已插入

 

SQL> commit;

 

提交完成

 

SQL> insert into testtab2 values('testtab2');

 

1 已插入

 

SQL> commit;

 

提交完成

 

SQL>

 

2.验证插入的数据:

 

SQL> select * from testtab1;

 

NAME1

----------

testtab1

 

SQL> select * from testtab2;

 

NAME2

----------

testtab2

 

SQL>

 

3.主要的c# 代码:

using ORAC = System.Data.OracleClient;

private void button1_Click(object sender, System.EventArgs e)

{

     try

              {

                   string str_Sql = @"begin open :cur1 for select * from testtab1;open :cur2 for select * from testtab2;end;";

                   ORAC.OracleCommand cmd = new ORAC.OracleCommand(str_Sql,this.oracleConnection1);

 

                   ORAC.OracleParameter parm1 = new ORAC.OracleParameter("cur1",ORAC.OracleType.Cursor);

                   parm1.Direction = ParameterDirection.Output;

                   cmd.Parameters.Add(parm1);

 

                   ORAC.OracleParameter parm2 = new ORAC.OracleParameter("cur2",ORAC.OracleType.Cursor);

                   parm2.Direction = ParameterDirection.Output;

                   cmd.Parameters.Add(parm2);

 

                   ORAC.OracleDataAdapter da = new ORAC.OracleDataAdapter();

                   da.SelectCommand = cmd;

 

                   DataSet ds = new DataSet();

 

                   da.Fill(ds);

 

                   this.dataGrid1.DataSource = ds.Tables[0].DefaultView;

 

                   this.dataGrid2.DataSource = ds.Tables[1].DefaultView;

 

 

 

 

              }

              catch(Exception ex)

              {

                   MessageBox.Show(ex.Message);

              }

              finally

              {

                   this.oracleConnection1.Close();

              }

             

}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页