Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generic data class
Message
From
16/01/2006 18:05:04
 
 
To
16/01/2006 17:50:34
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
01087043
Message ID:
01087369
Views:
10
I think all you have to do is use the .ToString for the Key:
                While loDictionaryEnumerator.MoveNext
                    oParameters2.Add(New OleDbParameter(loDictionaryEnumerator.Key.ToString(), loDictionaryEnumerator.Value))
                End While
Have you tried this?

~~Bonnie

>>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'.
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