473,320 Members | 1,883 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,320 software developers and data experts.

SqlDataReader::GetValue problems

This is what I am trying to do
double utmx = (double)
(pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_X8 3")));

and this is the exception that I get

System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="pdmssdeUpdate"
StackTrace:
at pdmssdeUpdate.updateSde.Main() in C:\Prem\PDMS
\C#PdmsSdeUpdate\pdmssdeUpdate\pdmssdeUpdate\updat eSde.cs:line 123
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

If I do

Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")));

I get

516098
Someone please help

Feb 8 '07 #1
4 4314


"Prem" <go************@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
This is what I am trying to do
double utmx = (double)
(pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_X8 3")));

and this is the exception that I get

System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="pdmssdeUpdate"
StackTrace:
at pdmssdeUpdate.updateSde.Main() in C:\Prem\PDMS
\C#PdmsSdeUpdate\pdmssdeUpdate\pdmssdeUpdate\updat eSde.cs:line 123
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

If I do

Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")));


But what is the type of the object returned from GetValue

Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")).GetType().Name);?David
Feb 8 '07 #2
The type is Int32

Thats what I get when I put in that line

On Feb 8, 3:54 pm, "David Browne" <davidbaxterbrowne no potted
m...@hotmail.comwrote:
"Prem" <godsmustbcr...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
This is what I am trying to do
double utmx = (double)
(pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_X8 3")));
and this is the exception that I get
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="pdmssdeUpdate"
StackTrace:
at pdmssdeUpdate.updateSde.Main() in C:\Prem\PDMS
\C#PdmsSdeUpdate\pdmssdeUpdate\pdmssdeUpdate\updat eSde.cs:line 123
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
If I do
Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")));

But what is the type of the object returned from GetValue

Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")).GetType().Name);?David

Feb 8 '07 #3
Ok I figured it out, you have to use
double utmX =
Convert.ToDouble(pSqlReader.GetValue(pSqlReader.Ge tOrdinal("UTM_X83")));

it will not do a cast

Thanks David

On Feb 8, 4:01 pm, "Prem" <godsmustbcr...@gmail.comwrote:
The type is Int32

Thats what I get when I put in that line

On Feb 8, 3:54 pm, "David Browne" <davidbaxterbrowne no potted

m...@hotmail.comwrote:
"Prem" <godsmustbcr...@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
This is what I am trying to do
double utmx = (double)
(pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_X8 3")));
and this is the exception that I get
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="pdmssdeUpdate"
StackTrace:
at pdmssdeUpdate.updateSde.Main() in C:\Prem\PDMS
\C#PdmsSdeUpdate\pdmssdeUpdate\pdmssdeUpdate\updat eSde.cs:line 123
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
If I do
Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")));
But what is the type of the object returned from GetValue
Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")).GetType().Name);?David

Feb 8 '07 #4
Prem wrote:
The type is Int32

Thats what I get when I put in that line

On Feb 8, 3:54 pm, "David Browne" <davidbaxterbrowne no potted
m...@hotmail.comwrote:
>"Prem" <godsmustbcr...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googleg roups.com...
>>This is what I am trying to do
double utmx = (double)
(pSqlReader.GetValue(pSqlReader.GetOrdinal("UTM_ X83")));
and this is the exception that I get
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="pdmssdeUpdate"
StackTrace:
at pdmssdeUpdate.updateSde.Main() in C:\Prem\PDMS
\C#PdmsSdeUpdate\pdmssdeUpdate\pdmssdeUpdate\upd ateSde.cs:line 123
at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.R unUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
If I do
Console.WriteLine(pSqlReader.GetValue(pSqlReader .GetOrdinal("UTM_X83")));
But what is the type of the object returned from GetValue

Console.WriteLine(pSqlReader.GetValue(pSqlReader.G etOrdinal("UTM_X83")).GetType().Name);?David

What you are doing is not really casting, but unboxing. The GetValue
method returns an object that contains the data, and getting the value
out of the object is called unboxing it.

When unboxing a value, you have to use the actual data type that the
object is containing. Therefore you have to unbox it using the int data
type, then you can cast it to a double:

double utmx =
(double)(int)(pSqlReader.GetValue(pSqlReader.GetOr dinal("UTM_X83")));

Or you can use the GetInt32 method instead, so that you don't have to
unbox the value:

double utmx =
(double)(pSqlReader.GetInt32(pSqlReader.GetOrdinal ("UTM_X83")));

--
Göran Andersson
_____
http://www.guffa.com
Feb 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rod | last post by:
Thanks in advance. I have two listboxes on a single asp page. I am trying to use sqldatareader to populate both using two seperate sql stored procs. I can populate each box seperately using...
5
by: TOm | last post by:
How do I bind a SqlDataReader to a dropdownlist box? I know how to construct a SqlDataReader dr and get the values. Buit how do I bind it to a DropDownList box in C#? This does not work ...
4
by: T!LT3D | last post by:
Hi I'm trying to convert data automatically from a SqlDataReader into the correct type for its class property, it goes something like this but is reported syntactilly incorrect.... MyField =...
2
by: louise raisbeck | last post by:
Is there any way to use GetValue on a sqldatareader.Read() by specifying column names instead of column numbers (or another method)?
2
by: SQL | last post by:
I'm new at this, so please forgive me if my question has a simple answer to it. I'm trying to get a value out of a SqlDataReader. Here is my code to do so: Dim mySQLCommand As New...
5
by: c676228 | last post by:
Hi all, I am stuck with this problem. the code is like this: Dim sqlreader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) ...
3
by: SDRoy | last post by:
Hi Is there a limitation on how many rows can be fetched using a SqlDataReader in ASP.Net 2.0 ? -- Thanks, SDRoy
13
by: lithoman | last post by:
I'm stumped here. I run the procedure Batch_Select against the database with @ID=18 and I get the expected data. When it loads into a SqlDataReader, it gets messed up somehow. Initially, after the...
3
by: Dom | last post by:
Still teaching myself about SQLDataReader and associated classes. I have to say, the new HELP screens from MS are just about useless!! Let's assume I have just read some records from a table...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.