Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parameterization of a query
Message
De
12/09/2010 18:33:51
 
 
À
12/09/2010 16:56:36
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01480890
Message ID:
01480915
Vues:
39
>I don't know about other back ends.

So far, I have adjusted my framework to support VFP, SQL Server, DBaseIV and SQL Anywhere. When I have to add a parameter, where I construct my SQL command, I can call a ParameterAddSQL() method which would add the proper syntax in the command such as:
        ' Add a parameter in the SQL with a proper syntax depending on the backend
        ' expC1 Field
        Public Function ParameterAddSQL(ByVal tcField As String) As String
            Dim lcString As String = ""

            ' Different backends handle it differently
            Select Case nBackend

                ' Visual FoxPro
                Case 1
                    lcString = "?"

                    ' SQL Server
                Case 2
                    lcString = "@" + tcField

                    ' SQL Anywhere
                Case 4
                    lcString = "?"

            End Select

            Return lcString
        End Function
An example would be:
            loDataProvider.ParameterAdd("Numero", oProcess.nNoMember, , "Member", "Numero")
            If Not loDataProvider.SQLExec("SELECT Member.NoType " + _
             "FROM Member " + _
             "WHERE Member.Numero=" + loDataProvider.ParameterAddSQL("Numero") ) Then
                Return False
            End If
I am still not sure however if I could change ParameterAddSQL() to adjust the string based on the type of connection instead such as:
        ' Add a parameter in the SQL with a proper syntax depending on the backend
        ' expC1 Field
        Public Function ParameterAddSQL(ByVal tcField As String) As String
            Dim lcString As String = ""

            ' Different SQL mode handle it differently
            Select Case nSQLMode

                ' OleDb
                Case 1
                    lcString = "?"

                    ' SQL client
                Case 2
                    lcString = "@" + tcField

                    ' ODBC
                Case 3
                    lcString = "?"

            End Select

            Return lcString
        End Function
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform