Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generic data class
Message
From
16/01/2006 17:50:34
 
 
To
16/01/2006 17:11:07
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01087043
Message ID:
01087366
Views:
11
>Perhaps you need to change the way you use the oParameters collection or, instead have it be a Hashtable ... you'd be passing it a "key" (the parameter name) and "value" (the parameter value) anyway, so it would work the similarly to the way you have it now. Then your Framework.Data class can build the correct type of parameters from the hashtable.

This is an interesting approach. I already tried something like that earlier and faced the same reaction. Here is how I did it:
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 Hashtable
    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
    Private oParameters2 As New Collection

    ' 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
        Dim loDictionaryEnumerator As IDictionaryEnumerator = oParameters.GetEnumerator
        cConnectionString = tcConnection
        Select Case tnConnType
            Case 1
                oConnection = New OleDbConnection(tcConnection)
                oDataAdapter = New OleDbDataAdapter
                oCommand = New OleDbCommand
                oDataParameter = New OleDbParameter
                While loDictionaryEnumerator.MoveNext
                    oParameters2.Add(New OleDbParameter(loDictionaryEnumerator.Key, loDictionaryEnumerator.Value))
                End While
            Case 2
                oConnection = New SqlConnection(tcConnection)
                oDataAdapter = New SqlDataAdapter
                oCommand = New SqlCommand
                oDataParameter = New SqlParameter
                While loDictionaryEnumerator.MoveNext
                    oParameters2.Add(New SqlParameter(loDictionaryEnumerator.Key, loDictionaryEnumerator.Value))
                End While
            Case 3
                oConnection = New OdbcConnection(tcConnection)
                oDataAdapter = New OdbcDataAdapter
                oCommand = New OdbcCommand
                oDataParameter = New OdbcParameter
                While loDictionaryEnumerator.MoveNext
                    oParameters2.Add(New OdbcParameter(loDictionaryEnumerator.Key, loDictionaryEnumerator.Value))
                End While
        End Select
        Return oConnection
    End Function

End Class
But, this generates an error:

Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(name As String, dataType As System.Data.OleDb.OleDbType)': Argument matching parameter 'name' narrows from 'Object' to 'String'.
'Public Sub New(name As String, dataType As System.Data.OleDb.OleDbType)': Argument matching parameter 'dataType' narrows from 'Object' to 'System.Data.OleDb.OleDbType'.
'Public Sub New(name As String, value As Object)': Argument matching parameter 'name' narrows from 'Object' to 'String'.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform