ConnectingToOracleUsingVSCore

 public static string GetOracleConnection(string PROPERTY_NO)

        {

            OracleConnection conn = new OracleConnection("Data Source=NameOfTheDB; User Id=UserId; Password=password;");

            DataSet dataSet = new DataSet("PPResultSet");

            OracleCommand cmd = new OracleCommand();

           

            cmd.CommandText = "procName";

            cmd.CommandType = CommandType.StoredProcedure;


            cmd.Parameters.Add("Column1", OracleDbType.Varchar2, "NULL", ParameterDirection.Input);

            cmd.Parameters.Add("Column2", OracleDbType.Varchar2, "NULL", ParameterDirection.Input);

           //In this case we are returning data using refcursor. 

            cmd.Parameters.Add("IO_CURSOR", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

          

            //To call using a query

            //cmd.CommandText = "Select * from Table  where rownum < 10";

            //Ends


            cmd.Connection = conn;

            conn.Open();

            using (OracleDataAdapter dataAdapter = new OracleDataAdapter())

            {

                dataAdapter.SelectCommand = cmd;

                dataAdapter.Fill(dataSet);

            }

            string xml = dataSet.GetXml();

            return xml;    

        }


No comments:

Post a Comment