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 ClassIn 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.
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 IfBut, 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.