Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ExecuteScalar(); with Oracle

Status
Not open for further replies.

WynneSMI

Programmer
Dec 16, 2002
76
US
I'm having an issue with getting the result from and ExecuteScalar with an Oracle Db. No matter what type (int, long, etc.) I tell it to return, it always throws an exception. I have tried this:

int count = (int) SQLCommand.ExecuteScalar();

Along with many other options but nothing seems to work. The query runs fine if I run it directly against the Db. I'm use to using a SQL Server Db and don't have much experience with Oracle back-end Db. Does anyone know what is going on here?!?! Thanks.
 
There are two command objects an SQL and OLEDB, the sql command object is specifically optimized for use with Microsoft SQL server. For any other server you will need to use an OleDBCommand.

Neither of the command objects mentioned have a stative method ExecuteScaler so you will have to icreate an instance variable as shown below

Code:
OleDbConnection OracleCn = new OleDbConnection("Your connection string, to Oracle Db");  

OleDbCommand = new OleDbCommand("Your command text",OracleCn);

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top