PC Review


Reply
Thread Tools Rate Thread

Convert OracleDbType.Decimal to C# decimal

 
 
MartinKK
Guest
Posts: n/a
 
      20th Aug 2009
Hi all,
I have a problem with converting OracleDbType.Decimal to System.Decimal. I
have the following code:
....(class)
public decimal speed;
OracleCommand cmd = new OracleCommand("GETNORM", dataCa.connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("return", OracleDbType.Int32).Direction =
ParameterDirection.ReturnValue;
cmd.Parameters.Add("CODE", OracleDbType.Decimal).Value = idSubject;
cmd.Parameters.Add("OUTSPEED", OracleDbType.Decimal).Direction =
ParameterDirection.Output;
cmd.ExecuteNonQuery();
this.speed = (Decimal)cmd.Parameters["OUTSPEEDVALUE"].Value;
....
The last line causes runtime error: Specified type-cast is invalid (I'm
translating from Czech language). In VS2008 debug I see, that
"cmd.Parameters["OUTSPEEDVALUE"].Value" has value (OUTSPEEDVALUE = 62).
My question is: How can I assign value from Oracle parameter to .NET (C#)
variable.
I'm unhappy 2 days.
Thanks
Martin
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      20th Aug 2009
MartinKK schrieb:
> Hi all,
> I have a problem with converting OracleDbType.Decimal to System.Decimal. I
> have the following code:
> ....(class)
> public decimal speed;
> OracleCommand cmd = new OracleCommand("GETNORM", dataCa.connection);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("return", OracleDbType.Int32).Direction =
> ParameterDirection.ReturnValue;
> cmd.Parameters.Add("CODE", OracleDbType.Decimal).Value = idSubject;
> cmd.Parameters.Add("OUTSPEED", OracleDbType.Decimal).Direction =
> ParameterDirection.Output;
> cmd.ExecuteNonQuery();
> this.speed = (Decimal)cmd.Parameters["OUTSPEEDVALUE"].Value;
> ....
> The last line causes runtime error: Specified type-cast is invalid (I'm
> translating from Czech language). In VS2008 debug I see, that
> "cmd.Parameters["OUTSPEEDVALUE"].Value" has value (OUTSPEEDVALUE = 62).
> My question is: How can I assign value from Oracle parameter to .NET (C#)
> variable.
> I'm unhappy 2 days.
> Thanks
> Martin


What's the data type of cmd.Parameters["OUTSPEEDVALUE"].Value? (quick
watch or assign to Object variable) I don't see a special OracleDecimal
data type inside the System.Data.OracleClient namespace. Only
OracleNumber, but there, conversion to Decimal is defined and should
work then.


Armin

--
https://epetitionen.bundestag.de/ind...;petition=4958
 
Reply With Quote
 
MartinKK
Guest
Posts: n/a
 
      20th Aug 2009


"Armin Zingler" wrote:

> MartinKK schrieb:
> > Hi all,
> > I have a problem with converting OracleDbType.Decimal to System.Decimal. I
> > have the following code:
> > ....(class)
> > public decimal speed;
> > OracleCommand cmd = new OracleCommand("GETNORM", dataCa.connection);
> > cmd.CommandType = CommandType.StoredProcedure;
> > cmd.Parameters.Add("return", OracleDbType.Int32).Direction =
> > ParameterDirection.ReturnValue;
> > cmd.Parameters.Add("CODE", OracleDbType.Decimal).Value = idSubject;
> > cmd.Parameters.Add("OUTSPEED", OracleDbType.Decimal).Direction =
> > ParameterDirection.Output;
> > cmd.ExecuteNonQuery();
> > this.speed = (Decimal)cmd.Parameters["OUTSPEEDVALUE"].Value;
> > ....
> > The last line causes runtime error: Specified type-cast is invalid (I'm
> > translating from Czech language). In VS2008 debug I see, that
> > "cmd.Parameters["OUTSPEEDVALUE"].Value" has value (OUTSPEEDVALUE = 62).
> > My question is: How can I assign value from Oracle parameter to .NET (C#)
> > variable.
> > I'm unhappy 2 days.
> > Thanks
> > Martin

>
> What's the data type of cmd.Parameters["OUTSPEEDVALUE"].Value? (quick
> watch or assign to Object variable) I don't see a special OracleDecimal
> data type inside the System.Data.OracleClient namespace. Only
> OracleNumber, but there, conversion to Decimal is defined and should
> work then.
>
>
> Armin
>
> --
> https://epetitionen.bundestag.de/ind...;petition=4958
>

Hi,
I'm sorry, there is error. Right is:
cmd.Parameters.Add("OUTSPEEDVALUE", OracleDbType.Decimal).Direction =
ParameterDirection.Output;
Martin

 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      20th Aug 2009
MartinKK schrieb:
>> What's the data type of cmd.Parameters["OUTSPEEDVALUE"].Value? (quick
>> watch or assign to Object variable) I don't see a special OracleDecimal
>> data type inside the System.Data.OracleClient namespace. Only
>> OracleNumber, but there, conversion to Decimal is defined and should
>> work then.
>>
>>
>>

> Hi,
> I'm sorry, there is error. Right is:
> cmd.Parameters.Add("OUTSPEEDVALUE", OracleDbType.Decimal).Direction =
> ParameterDirection.Output;
> Martin
>


Yes, but it doesn't answer my question.

Armin

--
https://epetitionen.bundestag.de/ind...;petition=4958
 
Reply With Quote
 
New Member
Join Date: Sep 2009
Posts: 1
 
      30th Sep 2009
Have you tried this.speed = (Decimal)(OracleDecimal)cmd.Parameters["OUTSPEEDVALUE"].Value;

The first () calls a type conversion to OracleDecimal then the second converts to Decimal.

There is also the Convert.ToDecimal(cmd.Parameters["OUTSPEEDVALUE"].Value) which will skip the double type conversion.

Give them a try.

Last edited by datavalue; 30th Sep 2009 at 02:15 AM.. Reason: Additional point
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I convert decimal commas to decimal points? =?Utf-8?B?UGV0ZXlsZXBpZXU=?= Microsoft Excel Misc 0 2nd Oct 2007 10:11 PM
How to convert Decimal number with comma(,) as decimal separator to dot(.) Domac Microsoft Access 5 10th May 2006 02:12 PM
How to convert Decimal number with comma(,) as decimal separator to dot(.) Domac Microsoft Access 1 10th May 2006 01:04 PM
How to convert Decimal number with comma(,) as decimal separator to dot(.) Domac Microsoft Access Forms 1 10th May 2006 01:04 PM
How to convert Decimal number with comma(,) as decimal separator to dot(.) Domac Microsoft Access Reports 1 10th May 2006 01:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:11 AM.