473,398 Members | 2,427 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,398 software developers and data experts.

Cast to Int and Decimal

RP
I want to Cast the following code lines.

[Cast To Int]
Product.ProductID = dvProduct[0]["ProductID"].ToString();

[Cast To Decimal]
Product.UnitPrice = dvProduct[0]["UnitPrice"].ToString();

dvProduct is a DataView.

Oct 24 '07 #1
1 1990
Since it isn't clear what these values are, your best bet may be
Convert:
int prodId = Convert.ToInt32(dvProduct[0]["ProductID"]);
decimal unitPrice = Convert.ToDecimal(dvProduct[0]
["UnitPrice"]);

If the data-types are known to be OK, you might have been able to
simply cast directly:

int prodId = (int) dvProduct[0]["ProductID"];
decimal unitPrice = (decimal)
Convert.ToDecimal(dvProduct[0]["UnitPrice"];

Marc

Oct 24 '07 #2

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

Similar topics

0
by: Aaron W. West | last post by:
Fun with CAST! (Optimized SQLServerCentral script posts) I found some interesting "tricks" to convert binary to hexadecimal and back, which allow doing 4 or 8 at a time. Test code first: --...
3
by: Mike | last post by:
I am using MS-Access as a front end for my MS-SQL DB. I have a sql view that uses the following: SELECT TOP 100 PERCENT RECID, PATNUMBER AS , SVCCODE AS , QTY, PROF_CHRGS AS , AMOUNT,...
3
by: Harry Keck | last post by:
I would imagine that this is a pretty trivial operation, but I can not figure out how to cast a string variable to a Decimal. I tried Decimal dVariable = (Decimal)strStringVariable, but it does not...
6
by: Nick Weekes | last post by:
Hi all, I am trying to cast a Double (its actually the NextDouble method of the Random class, but could be any type of number) to a Type via its name. Im trying the following syntax: ...
3
by: .Net Sports | last post by:
I have a variable that is part of my dataset (a double int datatype), and I need to use this variable in an ItemDataBound for a datagrid. When debugging and looking at the StackTrace, the Specified...
1
by: .Net Sports | last post by:
IN a datagrid code behind, I'm getting a "Specified cast is not valid" error price = (Decimal)(rowData); which was initialized as: Decimal price;
4
by: TheSteph | last post by:
Why do I get an exception "The specified cast is not valid" ??? Is that a bug or do I miss something ? object DecimalObject = 1; decimal TmpDecimal; TmpDecimal = (decimal)DecimalObject;
3
by: Dan Holmes | last post by:
i have a datareader that pulls a field of type numeric(18, 0). the debugger shows the field as {decimal}. I want to cast it to an int. This doesn't work (int)dr:. Is that because the definition...
1
by: skhuon | last post by:
Hi, when I divide Sum (AMT_NET_GAAP_GNLS)/Sum (AMT_UPB_FM) and these two fields are decimal fields, the results is 0 I know there is a way to cast the decimal point but i keep on getting errors,...
2
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all how can I write a method that returns me true if is possible to cast an object to decimal nullable and false if not? Like public bool CanConvert(object obj) { return true if obj is...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.