Selecting Oracle LONG or LONG RAW using ODP.NET in C#

Selecting data using the Oracle Data Provider for .NET (ODP.NET) is quite simple, however, if you forget a simple step, you may end up selecting blank fields for your LONG or LONG RAW's.
As usual, you'll need the proper using clause (or else your code will be overly verbose):

using Oracle.DataAccess.Client;using System.Data;

Then in your code, simply do:

string connstr = "PutYourConnectionStringHere";
OracleConnection conn = new OracleConnection(connstr);
OracleCommand cmd = new OracleCommand("SELECT * FROM MYTABLE", connstr);
// next line says to fetch first 1000 characters of LONG or LONG RAW fields.  If you omitted this, it would bring back blank fields instead.
cmd.InitialLONGFetchSize = 1000;
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter(cmd);
// use the data adapter to fill the dataset
da.fill(ds);
// now if any results came back, ds.Tables[0] will have your data.

At this point, you should be able to use the data, as you would any other datasource.

 

Share this article!

Follow us!

Find more helpful articles: