Private oCommand As IDbCommand = NothingBasically, all my data provider objects are defined as is in order to allow me to work with several backends. So, other examples are as follow:
Private oDataAdapter As IDbDataAdapter = Nothing Private oDataParameter As IDbDataParameter = Nothing Private oDataReader As IDataReader = NothingBut, in a custom method named ExecuteNonQuery(), I need to be able to assign a parameter to the oCommand object. Because this is a generic way, I end up with an error. Here is the code of the method:
' Execute a non query Public Function ExecuteNonQuery() As Boolean Dim lcCommandText As String = "" Dim llSuccess As Boolean = False Dim loStringBuilderHeaderList As StringBuilder = New StringBuilder() If Not InitializeDataObject("") Then Return False End If Try ' Get all commands For Each lcCommandText In oCommandText loStringBuilderHeaderList.Append(lcCommandText + oApp.cCR) Next oCommandText.Clear() ' Execute the commands oCommand.CommandType = CommandType.StoredProcedure oCommand.CommandText = "ExecScript" oCommand.Parameters.Add("myScript", OleDbType.Char).Value = loStringBuilderHeaderList.ToString oCommand.ExecuteNonQuery() llSuccess = True Catch loError As Exception DataError(loError, oApp.Debug(loStringBuilderHeaderList.ToString + ErrorDetail())) End Try Return llSuccess End FunctionThe oCommand.Parameters line generates an error "Too many arguments to 'Public Function Add(value As Object) As Integer' at design time. However, if I initialize loCommand as this:
Dim loCommand As OleDbCommand = oCommand.Connection.CreateCommand()and use a local syntax for the command object such as this:
loCommand.Parameters.Add("myScript", OleDbType.Char).Value = loStringBuilderHeaderList.ToString
This will work.