J
Jonathan Hornberger
I would like to use the SqlHelperParameterCache.GetSpParameterSet in order to define/retrieve my parameters for my Update, Insert and Delete commands. It looks like it is all good, but when I try and add the returned parameters to the command object, I get the following error:
System.InvalidCastException: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter[] objects.
Any ideas? Can this be done? I almost started singing the praises of the DAAB, maybe I can if someone can help.
Here is my code:
Dim cn As New SqlConnection(m_cnnStr)
Dim cmdUpdate As SqlCommand = cn.CreateCommand
Dim arParams() As SqlParameter
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_UpdateCustomer")
cmdUpdate.CommandType = CommandType.StoredProcedure
cmdUpdate.CommandText = "sp_UpdateCustomer"
cmdUpdate.Parameters.Add(arParams)
Dim cmdInsert As SqlCommand = cn.CreateCommand
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_InsertCustomer")
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.CommandText = "sp_InsertCustomer"
cmdInsert.Parameters.Add(arParams)
Dim cmdDelete As SqlCommand = cn.CreateCommand
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_DeleteCustomer")
cmdDelete.CommandText = "sp_DeleteCustomer"
cmdDelete.CommandType = CommandType.StoredProcedure
cmdDelete.Parameters.Add(arParams)
Dim da As New SqlDataAdapter
da.UpdateCommand = cmdUpdate
da.InsertCommand = cmdInsert
da.DeleteCommand = cmdDelete
da.Update(m_dtCustomers)
System.InvalidCastException: The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter[] objects.
Any ideas? Can this be done? I almost started singing the praises of the DAAB, maybe I can if someone can help.
Here is my code:
Dim cn As New SqlConnection(m_cnnStr)
Dim cmdUpdate As SqlCommand = cn.CreateCommand
Dim arParams() As SqlParameter
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_UpdateCustomer")
cmdUpdate.CommandType = CommandType.StoredProcedure
cmdUpdate.CommandText = "sp_UpdateCustomer"
cmdUpdate.Parameters.Add(arParams)
Dim cmdInsert As SqlCommand = cn.CreateCommand
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_InsertCustomer")
cmdInsert.CommandType = CommandType.StoredProcedure
cmdInsert.CommandText = "sp_InsertCustomer"
cmdInsert.Parameters.Add(arParams)
Dim cmdDelete As SqlCommand = cn.CreateCommand
arParams = SqlHelperParameterCache.GetSpParameterSet(m_cnnStr, "sp_DeleteCustomer")
cmdDelete.CommandText = "sp_DeleteCustomer"
cmdDelete.CommandType = CommandType.StoredProcedure
cmdDelete.Parameters.Add(arParams)
Dim da As New SqlDataAdapter
da.UpdateCommand = cmdUpdate
da.InsertCommand = cmdInsert
da.DeleteCommand = cmdDelete
da.Update(m_dtCustomers)