Solved

Convert textbox to converting to insert to sql database

Posted on 2003-11-04
2
457 Views
Last Modified: 2007-12-19
Hi there.  I have a database table with a field type of money.  When I query the database and display the information in a text box I do the following to format the data correctly.

Note the name of the textbox is AvgRevenue
AvgRevenue.Text = ( (decimal)productDR["AvgRevenue"] ).ToString("C");

This works well when I receive the information from the database, but blows up when I go to insert it back to the database.  I insert back to my database with a method that looks like this.

AddProduct (string productName, decimal AvgRevenue)

What is the best way for me to convert the AvgRevenue textbox to a decimal ?  Also, what about other datatypes.  I am sure to run into similar problems with DateTime.

Thanks
0
Comment
Question by:mdaymond
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 250 total points
ID: 9681581
AddProduct("Car", Decimal.Parse(AvgRevenue.Text));

Most types have a Parse function that allows them to parse their type out of a string.

DateTime Purchased = DateTime.Parse(PurchaseDate.Text);
int Counter = Int32.Parse(Quantity.Text);
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9682757
Thanks for grading the question so quickly.

What did you not like about the answer that it was only given a B?
I answer questions because I enjoy it and if there's something else that you didn't get answered then let me know and I'll try my best.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question