C# System.Data.Common DbCommand and getting Datasets from Oracle


i found no oracle specific forum area, decided post here.

getting dataset oracle c# system.data.common library's dbcommand seems tricky task.

i using command object in project along dbproviderfactory , dbdataadapter because meant allow use same library multiple database providers, , don't have clutter data access layer of project separate classes accessing each individual database provider.

my problem is, stored procedures fetching data oracle require refcursor object added in parameters. however, dbtype library not contain definition object. using "object"-type not work.

i have read many places not have add refcursor parameter, endless failed attempts @ running command without refcursor object has brought me conclusion leaving out refcursor object not option when using system.data.common library.

here coded example connectionstring purposefully left out.

                dbconnection.open();

                //create command
                dbcommand dbcommand = providerfactory.createcommand();
                dbcommand.connection = dbconnection;
                dbcommand.commandtype = commandtype.storedprocedure;
                dbcommand.commandtext = "packageexample.go";

                //add number parameter command
                dbparameter parameter1 = dbcommand.createparameter();
                parameter1.parametername = "parmone";
                parameter1.dbtype = dbtype.int32;
                parameter1.value = 1;
                dbcommand.parameters.add(parameter1);

                //add refcursor parameter
                dbparameter parameter2 = providerfactory.createparameter();
                parameter2.parametername = "cur_out";
                parameter2.dbtype = dbtype.object;                  <<------ dbtype incorrect
                parameter2.direction = parameterdirection.output;
                dbcommand.parameters.add(parameter2);
                
                //use dataadapter fill dataset results
                dbdataadapter adapter = providerfactory.createdataadapter();
                adapter.selectcommand = dbcommand;
                dataset dataset = new dataset();
                adapter.fill(dataset);
                datatable table1 = dataset.tables[0];
                dbconnection.close();

//the program fails error message stating there wrong types or wrong number of parameters. add exact error message in morning.

is possible somehow make code work, or system.data.common library no longer compatible oracle since removal of system.data.oracleclient library?

as final note: have tried oracles dataaccess library. not seem oracledbtype.refcursor can added compatible type system.data.dbtype. love wrong in assumption though.

//////////////////////////////////////////////////////////////////////////////

i found temporary solution should keep me level until more permanent structural change can implemented. using system.data.oracleclient library (yes know it's deprecated. solution temporary @ best), create dbparameter, cast oracleparameter. can add cursor oracletype enumeration.

code example:

                //add refcursor parameter
                oracleparameter parameter2 = (oracleparameter)providerfactory.createparameter();
                parameter2.parametername = "cur_out";
                parameter2.oracletype = oracletype.cursor;
                parameter2.direction = parameterdirection.output;
                dbcommand.parameters.add(parameter2);

///////////////////////////////////////////////////////////////////////////////////////////////////

i impressed quick rate of response on forum. thank help. use place if run bind again.

//////////////////////////////////////////////////////////////////////////////

i found temporary solution should keep me level until more permanent structural change can implemented. using system.data.oracleclient library (yes know it's deprecated. solution temporary @ best), create dbparameter, cast oracleparameter. can add cursor oracletype enumeration.

code example:

                //add refcursor parameter
                oracleparameter parameter2 = (oracleparameter)providerfactory.createparameter();
                parameter2.parametername = "cur_out";
                parameter2.oracletype = oracletype.cursor;
                parameter2.direction = parameterdirection.output;
                dbcommand.parameters.add(parameter2);

///////////////////////////////////////////////////////////////////////////////////////////////////

i impressed quick rate of response on forum. thank help. use place if run bind again.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'