Tuesday, February 14, 2012

CONVERT function use

I'll go right to the point:

I have a textbox in wich the user can seize a "money" value.

But when i'm doing the INSERT command, it fails and says I cannot implicitely convert nvarchar data (mytextbox.text) to money data.

I don't know how to handle this...


objCmd = New SqlCommand("INSERT INTO tbl_appel_service_pieces " & _
"(fld_nom_piece, fld_quantite, fld_prix, fld_description, fld_num_appel) " & _
"VALUES (@.fld_nom_piece, @.fld_quantite, @.fld_prix, @.fld_description, @.fld_num_appel)", objConn)

objCmd.Parameters.Add("@.fld_nom_piece", champsNomPiece.Text)
objCmd.Parameters.Add("@.fld_quantite", champsQuantite.Text)
objCmd.Parameters.Add("@.fld_prix", champsPrix.Text)
objCmd.Parameters.Add("@.fld_description", champsDescription.Text)
objCmd.Parameters.Add("@.fld_num_appel", champsNumAppel.Text)

objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()

afficherPieces()

How and where to do the conversion ? On the VALUES variable ?objCmd.Parameters.Add("@.fld_nom_piece", SqlDbType.Money)
objCmd.Parameters("@.fld_nom_piece").Value = System.Convert.ToDecimal(champsNomPiece.Text)|||Thanks ! It worked well.|||I have a similar problem in that I have a text box which holds a numeric value and when I try to insert the value into the numeric field in the SQL database I get the same error message.

I have tried the suggestion above but then I get another error message saying incorrect input.

Any idea's ??

Thanks

No comments:

Post a Comment