I have the following code that adds SQLParameter objects to an
SQLParameterCol lection object (well at least that's what I am trying to
do!!)
When the line of code runs that adds the parameter (colParams.Add) , the
actual function call (CreateSQLParam ) executes with no errors but the actual
".add" fails with an "Object reference not set to an instance of an object"
error. At first I thought it was maybe because I did not use the "New"
keyword when dimming colParams but there is no constructor for an
SQLParameterCol lection object so that was not the problem. The funny thing
was, this code worked EXACTLY as it is listed below EXCEPT I was using a
standard collection object previously instead of the SQLParameterCol lection
object. As soon as I converted it to the SQLParamaterCol lection object, I
started getting this error. I can not see where I am going awry but it must
be something quite simple!!!
Here is the code...
Dim colParams As SqlClient.SqlPa rameterCollecti on
' Set up the parameters
colParams.Add(C reateSQLParam(" @vcContractNo", ContractNo, SqlDbType.VarCh ar,
ParameterDirect ion.Input))
Function CreateSQLParam( ByVal sName As String, ByVal sValue As Object, ByVal
varType As System.Data.Sql DbType, ByVal varDir As ParameterDirect ion) As
SqlClient.SqlPa rameter
Dim objParam As SqlClient.SqlPa rameter
objParam = New SqlClient.SqlPa rameter()
objParam.Parame terName = sName
If IsNothing(sValu e) Then sValue = System.DBNull.V alue
objParam.Value = sValue
objParam.SqlDbT ype = varType
objParam.Direct ion = varDir
CreateSQLParam = objParam
End Function
SQLParameterCol lection object (well at least that's what I am trying to
do!!)
When the line of code runs that adds the parameter (colParams.Add) , the
actual function call (CreateSQLParam ) executes with no errors but the actual
".add" fails with an "Object reference not set to an instance of an object"
error. At first I thought it was maybe because I did not use the "New"
keyword when dimming colParams but there is no constructor for an
SQLParameterCol lection object so that was not the problem. The funny thing
was, this code worked EXACTLY as it is listed below EXCEPT I was using a
standard collection object previously instead of the SQLParameterCol lection
object. As soon as I converted it to the SQLParamaterCol lection object, I
started getting this error. I can not see where I am going awry but it must
be something quite simple!!!
Here is the code...
Dim colParams As SqlClient.SqlPa rameterCollecti on
' Set up the parameters
colParams.Add(C reateSQLParam(" @vcContractNo", ContractNo, SqlDbType.VarCh ar,
ParameterDirect ion.Input))
Function CreateSQLParam( ByVal sName As String, ByVal sValue As Object, ByVal
varType As System.Data.Sql DbType, ByVal varDir As ParameterDirect ion) As
SqlClient.SqlPa rameter
Dim objParam As SqlClient.SqlPa rameter
objParam = New SqlClient.SqlPa rameter()
objParam.Parame terName = sName
If IsNothing(sValu e) Then sValue = System.DBNull.V alue
objParam.Value = sValue
objParam.SqlDbT ype = varType
objParam.Direct ion = varDir
CreateSQLParam = objParam
End Function
Comment