473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

GetInt32 cast problem

Hello,
I am querying an oracle database to get the min and max of a field, and I'm trying to do it as efficiently as possible for my C# app. The code I have is as such:

command.CommandText="SELECT MIN(row_id), MAX(row_id) from my_table t where row_id is not null";
OracleDataReader reader=command.ExecuteReader();
int min=reader.GetOrdinal("min(row_id)");
int max=reader.GetOrdinal("min(row_id)");
reader.Read();
callnumber=reader.GetInt32(min);
maxnumber=reader.GetInt32(max);

However, I keep getting the following error when trying to set callnumber.

System.InvalidCastException: Specified cast is not valid..


callnumber and maxnumber are just standard C# ints, declared as class variables. Any help is appreciated.
Aug 10 '09 #1
3 4680
Plater
7,872 Expert 4TB
I would say the reader is not returning variables of type int32. Perhaps they are UInt32?
I have never seen a reader used like that with the GetOrdinal calls.
Why does GetOrdinal use the "min(row_id)" and GetInt32 uses just "min"?

Also, I'm sure it was just a copy/paste typo, but int max is also looking at the min value
Aug 11 '09 #2
GetOrdinal uses min(row_id) because that is the name of the column that is returned. I am using just the int 'min' with GetInt32 because that is the corresponding integer that reader.GetOrdinal("min(row_id)") returns.

I noticed that int max looks at the min just after I posted it :)
Aug 13 '09 #3
Plater
7,872 Expert 4TB
Ok for some reason I thought it was "min" not min.
What if you throw this line in there:
MessageBox.Show(reader.GetSqlValue(min).GetType(). ToString());
See what data type its trying to return?
Aug 13 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: A. W. Dunstan | last post by:
I'm porting some code to Visual C++ and have run into a problem - the compiler won't use a user-written cast operator. The code uses an envelope-letter approach to passing (potentially) large...
36
by: MSG | last post by:
The answer is neither. Use macros. #define ALLOC(size, type) ((type) *) malloc((size) * sizeof(type)) #define NEW(type, name, size) (type) * (name) = ALLOC((size), (type)) They are both ...
3
by: mike parr | last post by:
When reading from a data reader I have been using code like this : if (objDataReader.Read() == true) { intNewStatus = Convert.ToInt32(objDataReader); } But I've seen some code examples...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
0
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started....
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Mike Cooper | last post by:
Hello All! I am getting teh above error message on the following code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim dgt As...
6
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It...
2
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, How can I get around runtime error that says I can not explicit cast List<SubClassto ICollection<Class>? Generic List inhertis generic ICollection and Subclass inherits Class, then...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.