Getting multiple rows from oracle stored procedure and binding it to grid view

Last post 04-15-2008 6:34 AM by yeotumitsu@sify.com. 0 replies.

Sort Posts:

  • Getting multiple rows from oracle stored procedure and binding it to grid view

    04-15-2008, 6:34 AM

     

    To  get this stuff you need to create a Ref Cursor to return recordset.

                 create or replace PACKAGE Types AS

                TYPE cursor_type IS REF CURSOR;

                END Types;

    Now create a stored procedure to return multiple rows .

               create or replace

               PROCEDURE getAllCity(p_recordset OUT types.cursor_type) AS

               BEGIN

               OPEN p_recordset FOR

               select * from tbl_country;

              END getAllCity;

    Now put this code in your event.

                string strconn =  myDynconnStr;

                OracleConnection conn = new OracleConnection(strconn);

                OracleCommand objCmd = new OracleCommand();

                objCmd.Connection = conn;

                objCmd.CommandText = "getAllCity";

                objCmd.CommandType = CommandType.StoredProcedure;

                objCmd.Parameters.Add("p_recordset", OracleType.Cursor).Direction = ParameterDirection.Output;

                OracleDataAdapter odr = new OracleDataAdapter(objCmd);

                DataSet ds = new DataSet();

                odr.Fill(ds);

                GridView1.DataSource = ds.Tables[0];

                GridView1.DataBind();

    Hope it helps.

    -Manas

    =======================================
    If this post is useful to you, please mark it as answer.
Page 1 of 1 (1 items)