Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic data class
Message
De
16/01/2006 03:53:46
 
 
À
16/01/2006 02:06:43
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
01087043
Message ID:
01087071
Vues:
11
I have something working. Basically, the data class relies on the application framework to detect the default connection type. I can also set the data class connection type before calling the required method. Here is the code:
Imports System.Data
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data.Odbc

Public Class Data

    Public oDataSet As DataSet
    Public oDataView As DataView
    Public cSQL As String
    Public cConnectionString As String
    Public nCount As Integer
    Public oParameters As New Collection
    Public nSQLMode As Integer = Framework.App.nSQLMode
    Private oConnection As IDbConnection = Nothing
    Private oDataAdapter As IDbDataAdapter = Nothing
    Private oCommand As IDbCommand = Nothing
    Private oDataParameter As IDbDataParameter = Nothing

    ' SQL exec
    ' expC1 SQL command
    ' expO1 Connection
    Public Function SQLExec(ByVal tcSQL As String, ByVal tcConnection As String) As Boolean
        InitializeDataObject(nSQLMode, tcConnection, tcSQL)
.
.
.

    Public Function InitializeDataObject(ByVal tnConnType As Integer, ByVal tcConnection As String, _
     ByVal tcSql As String) As IDbConnection
        cConnectionString = tcConnection
        Select Case tnConnType
            Case 1
                oConnection = New OleDbConnection(tcConnection)
                oDataAdapter = New OleDbDataAdapter
                oCommand = New OleDbCommand
                oDataParameter = New OleDbParameter
            Case 2
                oConnection = New SqlConnection(tcConnection)
                oDataAdapter = New SqlDataAdapter
                oCommand = New SqlCommand
                oDataParameter = New SqlParameter
            Case 3
                oConnection = New OdbcConnection(tcConnection)
                oDataAdapter = New OdbcDataAdapter
                oCommand = New OdbcCommand
                oDataParameter = New OdbcParameter
        End Select
        Return oConnection
    End Function

End Class
In every method, such as SQLExec(), SQLInsert() and SQLDelete(), I am calling InitializeDataObject(nSQLMode, tcConnection, tcSQL) to instantiate the data objects based on the connection type.

However, I haven't updated it to support the parameter. Before I was able to do:
        Dim loDataProvider As Framework.Data = New Framework.Data
        loDataProvider.oParameters.Add(New OleDbParameter("@Username", lcUsername))
        If loDataProvider.SQLExec("SELECT Numero,Password,Session FROM " + tcTable + _
         " WHERE Username=?", tcConnection) = False Then
            Return False
        End If
But, I can no longer use that approach because that was assuming a OleDbParameter and at this point, the data objects are not instantiated. They will only be as soon as I do a call to a method such as SQLExec(). So, I guess I would need to replace the parameter line by calling a new method of the data class which would gather the parameter in a collection and once I will call a method, the InitializeDataObject() would be able to transfer that collection into oDataParameter.
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