I'm trying to convert legacy (VB.net) code that is using SqlConnection() to send parameters to a Stored Procedure. My main goal here is to rewrite this so that it utilizes OLEDB instead but I've come across multiple errors due to one of the parameters being a SqlDbType.Structured.
Is there a way to make SqlDbType.Structured pass through in a OLEDB connection?
Original Code:
mySQLConn = New SqlConnection()
mySQLConn.ConnectionString = strConn
mySQLConn.Open()
SQLcommand= New SqlCommand("stored_procedure", mySQLConn)
SQLcommand.CommandType = CommandType.StoredProcedure
SQLcommand.CommandTimeout = 0
mySqlTableTypeParam = SQLcommand.Parameters.Add("@InBoundData", SqlDbType.Structured) ' This line for reference
mySqlTableTypeParam.Value = AddUpdate
mySqlCleanupParam = SQLcommand.Parameters.Add("@sResponse", SqlDbType.VarChar)
mySqlCleanupParam.Value = strResponse
SQLcommand.ExecuteNonQuery()
My New OLEDB Code:
If oConnection Is Nothing Then oConnection = New Connection(Me.strConnection)
oConnection.Open()
cmd = New OleDbCommand
With cmd
.CommandType = CommandType.StoredProcedure
.CommandText = "stored_procedure"
.Connection = oConnection.Connection
.CommandTimeout = 0
.Parameters.Add("@sResponse", OleDbType.VarChar, 25)
.Parameters("@sResponse").Value = strResponse ' Expected to either be "N" or "Y"
.Parameters.Add("@InBoundData", System.Data.SqlDbType.Structured) ' I've run out of ideas
.Parameters("@InBoundData").Value = AddUpdate
End With
cmd.ExecuteNonQuery()
Errors:
Run Results: System Error:System.InvalidOperationException: Provider encountered an error while sending command parameter[0] '' value and stopped processing. Command parameter[1] '' data value could not be converted for reasons other than sign mismatch or data overflow. ---> System.Data.OleDb.OleDbException: Invalid character value for cast specification --- End of inner exception stack trace ---