Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generic data class
Message
From
16/01/2006 10:03:23
 
 
To
16/01/2006 03:53:46
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01087043
Message ID:
01087157
Views:
11
Haven't messed with it at all, but perhaps you may be able to use the IDataParameter interface for your paramaters.

~~Bonnie



>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.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform