Solved

Insert label.text into sql money column

Posted on 2010-09-17
5
603 Views
Last Modified: 2012-05-10
Hello,
I am using VB inserting data into a sql server table. one of the values is in a label, but needs to go into a "money" column.

I'm using the following parameter to convert it but it is not working. Any ideas?

error says,  input string not in correct format

 Cmd2.Parameters.Add(New SqlParameter("Amount", Convert.ToDouble(Label2.Text)))
0
Comment
Question by:mlg101
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 33706798
Have u tried CDbl?

 Cmd2.Parameters.Add(New SqlParameter("Amount", CDbl(Label2.Text)))
0
 
LVL 1

Author Comment

by:mlg101
ID: 33706831
i get the same error with that..
0
 
LVL 1

Author Comment

by:mlg101
ID: 33706839
I found out I had no value to the label, so that is why it didnt work, but your way worked when it had value. thanks.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33706843
hmmm, what about cdec then, convert to decimal

 Cmd2.Parameters.Add(New SqlParameter("Amount", CDec(Label2.Text)))

or format as currency

 Cmd2.Parameters.Add(New SqlParameter("Amount", Format(Label2.Text, "Currency")))

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33706844
fyi for your other conversions you may want to do


CBool - use this function to convert to Bool data type
CByte - use this function to convert to Byte data type
CChar - use this function to convert to Char data type
CDate - use this function to convert to Date type
CDbl - use this function to convert to Double data type
CDec - use this function to convert to Decimal data type
CInt - use this function to convert to Integer data type
CLng - use this function to convert to Long data type
CObj - use this function to convert to Object type
CShort - use this function to convert to Short data type
CSng - use this function to convert to Single data type
CString - use this function to convert to String data type
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

739 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