Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Universal ExecuteNonQuery() syntax
Message
De
09/07/2007 15:06:46
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Universal ExecuteNonQuery() syntax
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01238696
Message ID:
01238696
Vues:
72
I have a oCommand object defined as follow:
        Private oCommand As IDbCommand = Nothing
Basically, 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 = Nothing
But, 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 Function
The 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.

So, I need to adjust this method so it will work with the generic approach such as oCommand is defined. The method presently makes use of a OleDb approach for the parameter and this is not good as this method can be called from the OleDb provider, the SQL Client provider and so on. Anyone would know how to adjust this method so it will fit for all?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform