tags:

views:

111

answers:

5

I'm getting a datatable from sample query below in ORACLE "SELECT 1 AS X FROM ... "

when i select the X by using dr.Field("X"), it gives me error. I've found out that the it returns as decimal datatype.

Using the same statement in MSSQL has no problem, i've got the int datatype.

Any workaround or solution to this?

+1  A: 

Your front-end code is mis-autodetecting the type of the field. You should be able to override it to be an integer instead. Without more details on the language / etc being used, it's hard to be more specific.

Donnie
The tag says C#...
OMG Ponies
A: 

I don't have my Oracle books here at home, but an explicit convert or cast to integer would probably be the way to go. (Speaking of the Oracle query, not your C# that retrieves the result, although you could convert there as well.) "1" is ambiguous, as far as Oracle is concerned.

Cylon Cat
+1  A: 

If you know the type of that column should be an int and assuming it's not null:

int x = Convert.ToInt32 (dr.Field ["X"]);

This will not have any effect with other DB providers that return an int for that column.

If you want to change your Oracle query to return an int instead:

SELECT CAST(1 AS INTEGER) FROM ...
Gonzalo
A: 

Gonzalo,

your second option doesn't work, SELECT CAST(1 AS INTEGER) FROM ..., it will display in the datatable as a decimal.

A: 

it's ok now if i use: dr.Field<decimal?>("X")

sReas