I'm using a stored procedure and a parameterized command to insert into my database. I'm a bit new at using parameterized input so I'm hoping that I'm just missing something simple here. I'm running into a problem with my numeric (and possibly float) data types during the insert. The error that I'm getting is "The precision is invalid." After investigating this I found out that I need to specify precision and scale and I believe that I'm doing it correctly but I'm not positive. Here's what I've got so far:
Dim insertBuildingCmd, insertBuildingParam
Set insertBuildingCmd = Server.CreateObject("ADODB
.Command")
insertBuildingCmd.ActiveCo
nnection = DB_CONN_STRING
insertBuildingCmd.CommandT
ext = "sproc_building_insert"
insertBuildingCmd.CommandT
ype = 4
' Set parameters
Set insertBuildingParam = insertBuildingCmd.CreatePa
rameter("@
Name",200,
1,500)
insertBuildingCmd.Paramete
rs.Append insertBuildingParam
insertBuildingCmd.Paramete
rs("@Name"
) = Request.Form("formName")
Set insertBuildingParam = Nothing
(...several more text parameters)
Set insertBuildingParam = insertBuildingCmd.CreatePa
rameter("@
Lat",5,1,8
)
insertBuildingCmd.Paramete
rs.Append insertBuildingParam
If Request.Form("formLat") <> "" Then
insertBuildingCmd.Paramete
rs("@Lat")
= Request.Form("formLat")
insertBuildingCmd.Paramete
rs("@Lat")
.Precision
= 53
Else
insertBuildingCmd.Paramete
rs("@Lat")
= Null
End If
Set insertBuildingParam = Nothing
Set insertBuildingParam = insertBuildingCmd.CreatePa
rameter("@
GLA",131,1
,9)
insertBuildingCmd.Paramete
rs.Append insertBuildingParam
If Request.Form("formGLA") <> "" Then
insertBuildingCmd.Paramete
rs("@GLA")
= Request.Form("formGLA")
insertBuildingCmd.Paramete
rs("@GLA")
.Precision
= 18
insertBuildingCmd.Paramete
rs("@GLA")
.NumericSc
ale = 2
Else
insertBuildingCmd.Paramete
rs("@GLA")
= Null
End If
Set insertBuildingParam = Nothing
(...quite a few more numeric parameters)
I wasn't sure if the float datatypes needed precision/scale information so I've tried it with and without and I still get the same error. On the chance that the parameter had to be appended *after* the Precision/Scale declarations, I've also tried rewriting the parameters as:
Set insertBuildingParam = insertBuildingCmd.CreatePa
rameter("@
GLA",131,1
,9)
If Request.Form("formGLA") <> "" Then
insertBuildingCmd.Paramete
rs("@GLA")
= Request.Form("formGLA")
insertBuildingCmd.Paramete
rs("@GLA")
.Precision
= 18
insertBuildingCmd.Paramete
rs("@GLA")
.NumericSc
ale = 2
Else
insertBuildingCmd.Paramete
rs("@GLA")
= Null
End If
insertBuildingCmd.Paramete
rs.Append insertBuildingParam
Set insertBuildingParam = Nothing
But all that gets me is an "Item cannot be found in the collection corresponding to the requested name or ordinal." error.
Can anyone point me in the right direction? Thanks very much!
Start Free Trial