In a For Each loop my VB program iterates over an collection.
Inside this loop I’m setting paramaters for the prepared statement.
Set param1 = cmd.CreateParameter("sync_id", adChar, adParamInput, Len(sync_id), sync_id)
Set param2 = cmd.CreateParameter("fieldname", adChar, adParamInput, Len(CName), CName)
Set param3 = cmd.CreateParameter("pvname", adChar, adParamInput, Len(pvname), pvname)
Set param4 = cmd.CreateParameter("value", adChar, adParamInput, Len(CNameVal), CNameVal)
And then appending them the Command Object.
cmd.Parameters.Append param1
cmd.Parameters.Append param2
cmd.Parameters.Append param3
cmd.Parameters.Append param4
When CNameVal (param4) is empty VB gives me an error: The paramater object is not defined properly.
I tried to solve this by checking CNameVal before creating the parameter:
If CNameVal = Empty Then
Set param4 = cmd.CreateParameter("value", adEmpty, adParamInput)
'Set param4 = cmd.CreateParameter("value")
'Set param4 = cmd.CreateParameter("value", adEmpty, adParamInput, Len(CNameVal), CNameVal)
Else
Set param4 = cmd.CreateParameter("value", adChar, adParamInput, Len(CNameVal), CNameVal)
End If
Neither of those lines solve problem. Any help appreciated!!
Len(Empty) = 0, which leads to an error. String length cannot be0.Correct practice here is to provide actual fixed length set in the database, not the length of the current string. I also doubt you need
adChar, you probably meantadVarChar.YourIfdoesn’t work becauseCNameVal = Emptyis never going to beTrue. The correct way of checking for Empty isIsEmpty(CNameVal).