problems in insert in classic asp (replace)

1

People, in my database, the column is set to numeric (18,2)

Then I have a field in a form that the person types the value and it goes to my table.

insert looks like this:

entrada = Replace(Request.form("entrada"),",",".") 

Only if the person enters the value with a semicolon, for example "100.328,74" it gives the following error:

  

"[Microsoft] [ODBC SQL Server Driver] [SQL Server] Can not   convert a char value to money. The syntax of the char value is   incorrect. "

If it types only the point: "100.328" value becomes 100,33 (display on site with formatnumber "

if the person types only the comma: "100,32" value goes right to database "100.32" and "100,32" appears on site, according to formatnumber

Any ideas?

I have no way to indoctrinate everyone who is entering the value to not use the point that separates the thousand / million

I would like to program to go the right amount.

Thank you!

    
asked by anonymous 26.09.2018 / 17:29

2 answers

1

This code will always return the value in the format accepted by the database. For example:

100.328,74 will 100328.74

100,32 or 100.32 will 100.32

100,3 will 100.3

In summary, if there are cents, the code separates the cents from the main value and joins the two again separated by a point, which is the accepted format for monetary values. If there are no cents, the value remains the same, only removing the points that separate the thousands:

100.328 will 100328

Code:

entrada = Request.form("entrada")

Set regEx = New RegExp
regEx.Pattern = "[.,]\d{1,2}$"
Set RegExRes = regEx.Execute(entrada)
Set regEx = Nothing

If RegExRes.Count > 0 Then

   centavos = RegExRes(0)
   centslen = len(centavos)
   centavos = replace(replace(centavos, ",", ""), ".", "")
   valor = replace(left(entrada, len(entrada)-centslen), ".", "")

   entrada = valor&"."&centavos

Else

   entrada = replace(entrada, ".", "")

End If
    
26.09.2018 / 18:51
-1

In this case you first need to remove the points, and then change the commas per point. Ex:

entrada = Replace(Replace(Request.form("entrada"),".",""),",",".")
    
26.09.2018 / 18:49