Solved

Convert textbox to converting to insert to sql database

Posted on 2003-11-04
2
455 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now