• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 619
  • Last Modified:

Insert label.text into sql money column

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
mlg101
Asked:
mlg101
  • 3
  • 2
1 Solution
 
rockiroadsCommented:
Have u tried CDbl?

 Cmd2.Parameters.Add(New SqlParameter("Amount", CDbl(Label2.Text)))
0
 
mlg101Author Commented:
i get the same error with that..
0
 
mlg101Author Commented:
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
 
rockiroadsCommented:
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
 
rockiroadsCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now