Results 1 to 11 of 11

Thread: Generic DbProviderFactory Access

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    Core namespace classes and code:

    vb Code:
    1. Namespace Core
    2.  
    3.     <Flags()> _
    4.     Public Enum ParameterUsage As Integer
    5.         [Select] = 1
    6.         [Insert] = 2
    7.         [Update] = 4
    8.         [Delete] = 8
    9.     End Enum
    10.  
    11. End Namespace
    12.  
    13.  
    14.  
    15.  
    16. Namespace Core
    17.  
    18.     Public Interface IFetchDataObject
    19.  
    20.         Function InitializeObject(ByVal dr As Core.SafeDataReader)
    21.  
    22.     End Interface
    23.  
    24. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    Core namespace classes and code:
    PART 1 CODE TO LONG FOR MESSAGE
    FOLLOWING CODE I CANNOT TAKE CREDIT FOR IT IS FROM THE CSLA.NET LIBRARY BY ROCKFORD LHOTKA
    VB Code:
    1. Imports System.Data
    2.  
    3. Namespace Core
    4.     <System.Diagnostics.DebuggerStepThrough()> _
    5.     Public Class SafeDataReader
    6.         Implements IDataReader
    7.  
    8.         Private mDataReader As IDataReader
    9.  
    10.         Protected ReadOnly Property DataReader() As IDataReader
    11.             <System.Diagnostics.DebuggerStepThrough()> _
    12.             Get
    13.                 Return mDataReader
    14.             End Get
    15.         End Property
    16.  
    17.         <System.Diagnostics.DebuggerStepThrough()> _
    18.         Public Sub New(ByVal dataReader As IDataReader)
    19.             mDataReader = dataReader
    20.         End Sub
    21.  
    22.         <System.Diagnostics.DebuggerStepThrough()> _
    23.         Public Overridable Function GetString(ByVal i As Integer) As String _
    24.           Implements IDataReader.GetString
    25.  
    26.             If mDataReader.IsDBNull(i) Then
    27.                 Return ""
    28.             Else
    29.                 Return mDataReader.GetString(i)
    30.             End If
    31.         End Function
    32.  
    33.         <System.Diagnostics.DebuggerStepThrough()> _
    34.         Public Function GetString(ByVal name As String) As String
    35.             Dim index As Integer = Me.GetOrdinal(name)
    36.             Return Me.GetString(index)
    37.         End Function
    38.  
    39.         <System.Diagnostics.DebuggerStepThrough()> _
    40.         Public Overridable Function GetValue(ByVal i As Integer) As Object Implements IDataReader.GetValue
    41.             If mDataReader.IsDBNull(i) Then
    42.                 Return Nothing
    43.             Else
    44.                 Return mDataReader.GetValue(i)
    45.             End If
    46.         End Function
    47.  
    48.         <System.Diagnostics.DebuggerStepThrough()> _
    49.         Public Function GetValue(ByVal name As String) As Object
    50.             Dim index As Integer = Me.GetOrdinal(name)
    51.             Return Me.GetValue(index)
    52.         End Function
    53.  
    54.         <System.Diagnostics.DebuggerStepThrough()> _
    55.         Public Overridable Function GetInt32(ByVal i As Integer) As Integer Implements IDataReader.GetInt32
    56.             If mDataReader.IsDBNull(i) Then
    57.                 Return 0
    58.             Else
    59.                 Return mDataReader.GetInt32(i)
    60.             End If
    61.         End Function
    62.  
    63.         <System.Diagnostics.DebuggerStepThrough()> _
    64.         Public Function GetInt32(ByVal name As String) As Integer
    65.             Dim index As Integer = Me.GetOrdinal(name)
    66.             Return Me.GetInt32(index)
    67.         End Function
    68.  
    69.         <System.Diagnostics.DebuggerStepThrough()> _
    70.         Public Overridable Function GetDouble(ByVal i As Integer) As Double Implements IDataReader.GetDouble
    71.             If mDataReader.IsDBNull(i) Then
    72.                 Return 0
    73.             Else
    74.                 Return mDataReader.GetDouble(i)
    75.             End If
    76.         End Function
    77.  
    78.         <System.Diagnostics.DebuggerStepThrough()> _
    79.         Public Function GetDouble(ByVal name As String) As Double
    80.             Dim index As Integer = Me.GetOrdinal(name)
    81.             Return Me.GetDouble(index)
    82.         End Function
    83.  
    84.         <System.Diagnostics.DebuggerStepThrough()> _
    85.         Public Overridable Function GetGuid(ByVal i As Integer) As Guid Implements IDataReader.GetGuid
    86.             If mDataReader.IsDBNull(i) Then
    87.                 Return Guid.Empty
    88.             Else
    89.                 Return mDataReader.GetGuid(i)
    90.             End If
    91.         End Function
    92.  
    93.         <System.Diagnostics.DebuggerStepThrough()> _
    94.         Public Function GetGuid(ByVal name As String) As Guid
    95.             Dim index As Integer = Me.GetOrdinal(name)
    96.             Return Me.GetGuid(index)
    97.         End Function
    98.  
    99.         <System.Diagnostics.DebuggerStepThrough()> _
    100.         Public Function Read() As Boolean Implements IDataReader.Read
    101.             Return mDataReader.Read
    102.         End Function
    103.  
    104.         <System.Diagnostics.DebuggerStepThrough()> _
    105.         Public Function NextResult() As Boolean Implements IDataReader.NextResult
    106.             Return mDataReader.NextResult()
    107.         End Function
    108.  
    109.         <System.Diagnostics.DebuggerStepThrough()> _
    110.         Public Sub Close() Implements IDataReader.Close
    111.             mDataReader.Close()
    112.         End Sub
    113.  
    114.         Public ReadOnly Property Depth() As Integer Implements System.Data.IDataReader.Depth
    115.             <System.Diagnostics.DebuggerStepThrough()> _
    116.             Get
    117.                 Return mDataReader.Depth
    118.             End Get
    119.         End Property
    120.  
    121.         Public ReadOnly Property FieldCount() As Integer Implements System.Data.IDataReader.FieldCount
    122.             <System.Diagnostics.DebuggerStepThrough()> _
    123.             Get
    124.                 Return mDataReader.FieldCount
    125.             End Get
    126.         End Property
    127.  
    128.         <System.Diagnostics.DebuggerStepThrough()> _
    129.         Public Overridable Function GetBoolean(ByVal i As Integer) As Boolean _
    130.           Implements System.Data.IDataReader.GetBoolean
    131.  
    132.             If mDataReader.IsDBNull(i) Then
    133.                 Return False
    134.             Else
    135.                 Return mDataReader.GetBoolean(i)
    136.             End If
    137.         End Function
    138.  
    139.         <System.Diagnostics.DebuggerStepThrough()> _
    140.         Public Function GetBoolean(ByVal name As String) As Boolean
    141.             Dim index As Integer = Me.GetOrdinal(name)
    142.             Return Me.GetBoolean(index)
    143.         End Function
    144.  
    145.         <System.Diagnostics.DebuggerStepThrough()> _
    146.         Public Overridable Function GetByte(ByVal i As Integer) As Byte Implements System.Data.IDataReader.GetByte
    147.             If mDataReader.IsDBNull(i) Then
    148.                 Return 0
    149.             Else
    150.                 Return mDataReader.GetByte(i)
    151.             End If
    152.         End Function
    153.  
    154.         <System.Diagnostics.DebuggerStepThrough()> _
    155.         Public Function GetByte(ByVal name As String) As Byte
    156.             Dim index As Integer = Me.GetOrdinal(name)
    157.             Return Me.GetByte(index)
    158.         End Function
    159.  
    160.         <System.Diagnostics.DebuggerStepThrough()> _
    161.         Public Overridable Function GetBytes(ByVal i As Integer, ByVal fieldOffset As Long, ByVal buffer() As Byte, ByVal bufferOffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataReader.GetBytes
    162.             If mDataReader.IsDBNull(i) Then
    163.                 Return 0
    164.             Else
    165.                 Return mDataReader.GetBytes(i, fieldOffset, buffer, bufferOffset, length)
    166.             End If
    167.         End Function
    168.  
    169.         <System.Diagnostics.DebuggerStepThrough()> _
    170.         Public Function GetBytes(ByVal name As String, ByVal fieldOffset As Long, ByVal buffer() As Byte, ByVal bufferOffset As Integer, ByVal length As Integer) As Long
    171.             Dim index As Integer = Me.GetOrdinal(name)
    172.             Return Me.GetBytes(index, fieldOffset, buffer, bufferOffset, length)
    173.         End Function
    174.  
    175.         <System.Diagnostics.DebuggerStepThrough()> _
    176.         Public Overridable Function GetChar(ByVal i As Integer) As Char Implements System.Data.IDataReader.GetChar
    177.             If mDataReader.IsDBNull(i) Then
    178.                 Return Char.MinValue
    179.             Else
    180.                 Dim myChar(0) As Char
    181.                 mDataReader.GetChars(i, 0, myChar, 0, 1)
    182.                 Return myChar(0)
    183.             End If
    184.         End Function

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  3. #3

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    Core namespace classes and code:
    PART 2 CODE TO LONG FOR MESSAGE
    FOLLOWING CODE I CANNOT TAKE CREDIT FOR IT IS FROM THE CSLA.NET LIBRARY BY ROCKFORD LHOTKA


    VB Code:
    1. <System.Diagnostics.DebuggerStepThrough()> _
    2.         Public Function GetChar(ByVal name As String) As Char
    3.             Dim index As Integer = Me.GetOrdinal(name)
    4.             Return Me.GetChar(index)
    5.         End Function
    6.  
    7.         <System.Diagnostics.DebuggerStepThrough()> _
    8.         Public Overridable Function GetChars(ByVal i As Integer, ByVal fieldOffset As Long, ByVal buffer() As Char, ByVal bufferOffset As Integer, ByVal length As Integer) As Long Implements System.Data.IDataReader.GetChars
    9.             If mDataReader.IsDBNull(i) Then
    10.                 Return 0
    11.             Else
    12.                 Return mDataReader.GetChars(i, fieldOffset, buffer, bufferOffset, length)
    13.             End If
    14.         End Function
    15.  
    16.         <System.Diagnostics.DebuggerStepThrough()> _
    17.         Public Function GetChars(ByVal name As String, ByVal fieldOffset As Long, ByVal buffer() As Char, ByVal bufferOffset As Integer, ByVal length As Integer) As Long
    18.             Dim index As Integer = Me.GetOrdinal(name)
    19.             Return Me.GetChars(index, fieldOffset, buffer, bufferOffset, length)
    20.         End Function
    21.  
    22.         <System.Diagnostics.DebuggerStepThrough()> _
    23.         Public Overridable Function GetData(ByVal i As Integer) As System.Data.IDataReader Implements System.Data.IDataReader.GetData
    24.             Return mDataReader.GetData(i)
    25.         End Function
    26.  
    27.         <System.Diagnostics.DebuggerStepThrough()> _
    28.         Public Function GetData(ByVal name As String) As System.Data.IDataReader
    29.             Dim index As Integer = Me.GetOrdinal(name)
    30.             Return Me.GetData(index)
    31.         End Function
    32.  
    33.         <System.Diagnostics.DebuggerStepThrough()> _
    34.         Public Overridable Function GetDataTypeName(ByVal i As Integer) As String Implements System.Data.IDataReader.GetDataTypeName
    35.             Return mDataReader.GetDataTypeName(i)
    36.         End Function
    37.  
    38.         <System.Diagnostics.DebuggerStepThrough()> _
    39.         Public Function GetDataTypeName(ByVal name As String) As String
    40.             Dim index As Integer = Me.GetOrdinal(name)
    41.             Return Me.GetDataTypeName(index)
    42.         End Function
    43.  
    44.         <System.Diagnostics.DebuggerStepThrough()> _
    45.         Public Overridable Function GetDateTime(ByVal i As Integer) As Date _
    46.           Implements System.Data.IDataReader.GetDateTime
    47.  
    48.             If mDataReader.IsDBNull(i) Then
    49.                 Return Date.MinValue
    50.             Else
    51.                 Return mDataReader.GetDateTime(i)
    52.             End If
    53.         End Function
    54.  
    55.         <System.Diagnostics.DebuggerStepThrough()> _
    56.         Public Function GetDateTime(ByVal name As String) As Date
    57.             Dim index As Integer = Me.GetOrdinal(name)
    58.             Return Me.GetDateTime(index)
    59.         End Function
    60.  
    61.         <System.Diagnostics.DebuggerStepThrough()> _
    62.         Public Overridable Function GetDecimal(ByVal i As Integer) As Decimal Implements System.Data.IDataReader.GetDecimal
    63.             If mDataReader.IsDBNull(i) Then
    64.                 Return 0
    65.             Else
    66.                 Return mDataReader.GetDecimal(i)
    67.             End If
    68.         End Function
    69.  
    70.         <System.Diagnostics.DebuggerStepThrough()> _
    71.         Public Function GetDecimal(ByVal name As String) As Decimal
    72.             Dim index As Integer = Me.GetOrdinal(name)
    73.             Return Me.GetDecimal(index)
    74.         End Function
    75.  
    76.         <System.Diagnostics.DebuggerStepThrough()> _
    77.         Public Overridable Function GetFieldType(ByVal i As Integer) As System.Type Implements System.Data.IDataReader.GetFieldType
    78.             Return mDataReader.GetFieldType(i)
    79.         End Function
    80.  
    81.         Public Function GetFieldType(ByVal name As String) As System.Type
    82.             Dim index As Integer = Me.GetOrdinal(name)
    83.             Return Me.GetFieldType(index)
    84.         End Function
    85.  
    86.         <System.Diagnostics.DebuggerStepThrough()> _
    87.         Public Overridable Function GetFloat(ByVal i As Integer) As Single Implements System.Data.IDataReader.GetFloat
    88.             If mDataReader.IsDBNull(i) Then
    89.                 Return 0
    90.             Else
    91.                 Return mDataReader.GetFloat(i)
    92.             End If
    93.         End Function
    94.  
    95.         <System.Diagnostics.DebuggerStepThrough()> _
    96.         Public Function GetFloat(ByVal name As String) As Single
    97.             Dim index As Integer = Me.GetOrdinal(name)
    98.             Return Me.GetFloat(index)
    99.         End Function
    100.  
    101.         <System.Diagnostics.DebuggerStepThrough()> _
    102.         Public Overridable Function GetInt16(ByVal i As Integer) As Short Implements System.Data.IDataReader.GetInt16
    103.             If mDataReader.IsDBNull(i) Then
    104.                 Return 0
    105.             Else
    106.                 Return mDataReader.GetInt16(i)
    107.             End If
    108.         End Function
    109.  
    110.         <System.Diagnostics.DebuggerStepThrough()> _
    111.         Public Function GetInt16(ByVal name As String) As Short
    112.             Dim index As Integer = Me.GetOrdinal(name)
    113.             Return Me.GetInt16(index)
    114.         End Function
    115.  
    116.         <System.Diagnostics.DebuggerStepThrough()> _
    117.         Public Overridable Function GetInt64(ByVal i As Integer) As Long Implements System.Data.IDataReader.GetInt64
    118.             If mDataReader.IsDBNull(i) Then
    119.                 Return 0
    120.             Else
    121.                 Return mDataReader.GetInt64(i)
    122.             End If
    123.         End Function
    124.  
    125.         <System.Diagnostics.DebuggerStepThrough()> _
    126.         Public Function GetInt64(ByVal name As String) As Long
    127.             Dim index As Integer = Me.GetOrdinal(name)
    128.             Return Me.GetInt64(index)
    129.         End Function
    130.  
    131.         Public Overridable Function GetName(ByVal i As Integer) As String Implements System.Data.IDataReader.GetName
    132.             Return mDataReader.GetName(i)
    133.         End Function
    134.  
    135.         <System.Diagnostics.DebuggerStepThrough()> _
    136.         Public Function GetOrdinal(ByVal name As String) As Integer _
    137.           Implements System.Data.IDataReader.GetOrdinal
    138.  
    139.             Return mDataReader.GetOrdinal(name)
    140.         End Function
    141.  
    142.         <System.Diagnostics.DebuggerStepThrough()> _
    143.         Public Function GetSchemaTable() As System.Data.DataTable Implements System.Data.IDataReader.GetSchemaTable
    144.             Return mDataReader.GetSchemaTable
    145.         End Function
    146.  
    147.         <System.Diagnostics.DebuggerStepThrough()> _
    148.         Public Function GetValues(ByVal values() As Object) As Integer Implements System.Data.IDataReader.GetValues
    149.             Return mDataReader.GetValues(values)
    150.         End Function
    151.  
    152.         Public ReadOnly Property IsClosed() As Boolean Implements System.Data.IDataReader.IsClosed
    153.             <System.Diagnostics.DebuggerStepThrough()> _
    154.             Get
    155.                 Return mDataReader.IsClosed
    156.             End Get
    157.         End Property
    158.  
    159.         <System.Diagnostics.DebuggerStepThrough()> _
    160.         Public Overridable Function IsDBNull(ByVal i As Integer) As Boolean Implements System.Data.IDataReader.IsDBNull
    161.             Return mDataReader.IsDBNull(i)
    162.         End Function
    163.  
    164.         <System.Diagnostics.DebuggerStepThrough()> _
    165.         Public Function IsDBNull(ByVal name As String) As Boolean
    166.             Dim index As Integer = Me.GetOrdinal(name)
    167.             Return Me.IsDBNull(index)
    168.         End Function
    169.  
    170.         Default Public Overloads ReadOnly Property Item(ByVal name As String) As Object Implements System.Data.IDataReader.Item
    171.             <System.Diagnostics.DebuggerStepThrough()> _
    172.             Get
    173.                 Dim value As Object = mDataReader.Item(name)
    174.                 If DBNull.Value.Equals(value) Then
    175.                     Return Nothing
    176.                 Else
    177.                     Return value
    178.                 End If
    179.             End Get
    180.         End Property
    181.  
    182.         Default Public Overridable Overloads ReadOnly Property Item(ByVal i As Integer) As Object Implements System.Data.IDataReader.Item
    183.             <System.Diagnostics.DebuggerStepThrough()> _
    184.             Get
    185.                 If mDataReader.IsDBNull(i) Then
    186.                     Return Nothing
    187.                 Else
    188.                     Return mDataReader.Item(i)
    189.                 End If
    190.             End Get
    191.         End Property
    192.  
    193.         Public ReadOnly Property RecordsAffected() As Integer Implements System.Data.IDataReader.RecordsAffected
    194.             <System.Diagnostics.DebuggerStepThrough()> _
    195.             Get
    196.                 Return mDataReader.RecordsAffected
    197.             End Get
    198.         End Property
    199.  
    200. #Region " IDisposable Support "
    201.  
    202.         Private disposedValue As Boolean     ' To detect redundant calls
    203.  
    204.         Protected Overridable Sub Dispose(ByVal disposing As Boolean)
    205.             If Not Me.disposedValue Then
    206.                 If disposing Then
    207.                     ' free unmanaged resources when explicitly called
    208.                     mDataReader.Dispose()
    209.                 End If
    210.  
    211.                 ' free shared unmanaged resources
    212.             End If
    213.             Me.disposedValue = True
    214.         End Sub
    215.  
    216.         Public Sub Dispose() Implements IDisposable.Dispose
    217.             ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
    218.             Dispose(True)
    219.             GC.SuppressFinalize(Me)
    220.         End Sub
    221.  
    222.         Protected Overrides Sub Finalize()
    223.             Dispose(False)
    224.         End Sub
    225.  
    226. #End Region
    227.  
    228.     End Class
    229.  
    230. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  4. #4

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    Core namespace classes and code:

    VB Code:
    1. Imports System.Data
    2. Imports System.Text
    3. Namespace Core
    4.  
    5.     Public Class CSSIDbParameter : Inherits Common.DbParameter
    6.         'Implements IDbDataParameter
    7.  
    8. #Region " Fields "
    9.  
    10.         Private m_Usage As Core.ParameterUsage
    11.  
    12.         Private m_IsNullable As Boolean = True
    13.         Private m_DbType As DbType = System.Data.DbType.String
    14.         Private m_Direction As ParameterDirection = ParameterDirection.Input
    15.         Private m_ParameterName As String = String.Empty
    16.         Private m_SourceColumn As String = String.Empty
    17.         Private m_SourceVersion As DataRowVersion = DataRowVersion.Default
    18.         Private m_Percision As Byte = 0
    19.         Private m_Scale As Byte = 0
    20.         Private m_Size As Integer = 0
    21.         Private m_Value As Object = Nothing
    22.         Private m_SourceColumnNullMapping As Boolean = False
    23.  
    24. #End Region
    25.  
    26. #Region " Constructors "
    27.  
    28.         <DebuggerStepThrough()> _
    29.         Public Sub New()
    30.             MyBase.New()
    31.         End Sub
    32.  
    33.         <DebuggerStepThrough()> _
    34.         Public Sub New(ByVal value As Object)
    35.             MyBase.New()
    36.             Me.Value = value
    37.         End Sub
    38.  
    39.         <DebuggerStepThrough()> _
    40.         Public Sub New(ByVal paramUsage As Core.ParameterUsage)
    41.             Me.New()
    42.             m_Usage = paramUsage
    43.         End Sub
    44.  
    45.         <DebuggerStepThrough()> _
    46.         Public Sub New(ByVal parameterName As String, _
    47.                        ByVal value As Object, _
    48.                        Optional ByVal paramUsage As Core.ParameterUsage = ParameterUsage.Select)
    49.             Me.New()
    50.             Me.ParameterName = parameterName
    51.             Me.Value = value
    52.             Me.ParameterUsage = paramUsage
    53.         End Sub
    54.  
    55.         <DebuggerStepThrough()> _
    56.         Public Sub New(ByVal parameterName As String, _
    57.                        ByVal dbType As DbType, _
    58.                        Optional ByVal paramUsage As Core.ParameterUsage = ParameterUsage.Select)
    59.             Me.New()
    60.             Me.ParameterName = parameterName
    61.             Me.DbType = dbType
    62.             Me.ParameterUsage = paramUsage
    63.         End Sub
    64.  
    65.         <DebuggerStepThrough()> _
    66.         Public Sub New(ByVal parameterName As String, _
    67.                        ByVal dbType As DbType, _
    68.                        ByVal size As Integer, _
    69.                        ByVal sourceColumn As String, _
    70.                        Optional ByVal paramUsage As Core.ParameterUsage = ParameterUsage.Select)
    71.             Me.New()
    72.             Me.ParameterName = parameterName
    73.             Me.DbType = dbType
    74.             Me.Size = size
    75.             Me.SourceColumn = sourceColumn
    76.             Me.ParameterUsage = paramUsage
    77.         End Sub
    78.  
    79.         <DebuggerStepThrough()> _
    80.         Public Sub New(ByVal parameterName As String, _
    81.                        ByVal dbType As DbType, _
    82.                        ByVal size As Integer, _
    83.                        Optional ByVal paramUsage As Core.ParameterUsage = ParameterUsage.Select)
    84.             Me.New()
    85.             Me.ParameterName = parameterName
    86.             Me.DbType = dbType
    87.             Me.Size = size
    88.             Me.ParameterUsage = paramUsage
    89.         End Sub
    90.  
    91.         <DebuggerStepThrough()> _
    92.         Public Sub New(ByVal parameterName As String, _
    93.                        ByVal dbType As DbType, _
    94.                        ByVal size As Integer, _
    95.                        ByVal direction As System.Data.ParameterDirection, _
    96.                        ByVal isNullable As Boolean, _
    97.                        ByVal percision As Byte, _
    98.                        ByVal scale As Byte, _
    99.                        ByVal sourceColumn As String, _
    100.                        ByVal sourceVersion As System.Data.DataRowVersion, _
    101.                        ByVal value As Object, _
    102.                        Optional ByVal paramUsage As Core.ParameterUsage = ParameterUsage.Select)
    103.             Me.New()
    104.             Me.ParameterName = parameterName
    105.             Me.DbType = dbType
    106.             Me.Size = size
    107.             Me.Direction = direction
    108.             m_IsNullable = isNullable
    109.             Me.Precision = percision
    110.             Me.Scale = scale
    111.             Me.SourceColumn = sourceColumn
    112.             Me.SourceVersion = sourceVersion
    113.             Me.Value = value
    114.             Me.ParameterUsage = paramUsage
    115.         End Sub
    116.  
    117. #End Region
    118.  
    119.         Public Property ParameterUsage() As Core.ParameterUsage
    120.             <DebuggerStepThrough()> _
    121.             Get
    122.                 Return m_Usage
    123.             End Get
    124.             <DebuggerStepThrough()> _
    125.             Set(ByVal value As Core.ParameterUsage)
    126.                 m_Usage = value
    127.             End Set
    128.         End Property
    129.  
    130.         Public Overrides Property DbType() As System.Data.DbType
    131.             <DebuggerStepThrough()> _
    132.             Get
    133.                 Return m_DbType
    134.             End Get
    135.             <DebuggerStepThrough()> _
    136.             Set(ByVal value As System.Data.DbType)
    137.                 m_DbType = value
    138.             End Set
    139.         End Property
    140.  
    141.         Public Overrides Property Direction() As System.Data.ParameterDirection
    142.             <DebuggerStepThrough()> _
    143.             Get
    144.                 Return m_Direction
    145.             End Get
    146.             <DebuggerStepThrough()> _
    147.             Set(ByVal value As System.Data.ParameterDirection)
    148.                 m_Direction = value
    149.             End Set
    150.         End Property
    151.  
    152.         Public Overrides Property IsNullable() As Boolean
    153.             <DebuggerStepThrough()> _
    154.             Get
    155.                 Return m_IsNullable
    156.             End Get
    157.             <DebuggerStepThrough()> _
    158.             Set(ByVal value As Boolean)
    159.                 m_IsNullable = value
    160.             End Set
    161.         End Property
    162.  
    163.         Public Overrides Property ParameterName() As String
    164.             <DebuggerStepThrough()> _
    165.             Get
    166.                 Return m_ParameterName
    167.             End Get
    168.             <DebuggerStepThrough()> _
    169.             Set(ByVal value As String)
    170.                 Dim sb As New StringBuilder(value)
    171.                 Select Case m_Usage
    172.                     Case Core.ParameterUsage.Insert
    173.                         sb.Append("_INSERT")
    174.                     Case Core.ParameterUsage.Update
    175.                         sb.Append("_UPDATE")
    176.                     Case Core.ParameterUsage.Delete
    177.                         sb.Append("_DELETE")
    178.                 End Select
    179.                 m_ParameterName = sb.ToString
    180.             End Set
    181.         End Property
    182.  
    183.         Public Overrides Property SourceColumn() As String
    184.             <DebuggerStepThrough()> _
    185.             Get
    186.                 Return m_SourceColumn
    187.             End Get
    188.             <DebuggerStepThrough()> _
    189.             Set(ByVal value As String)
    190.                 m_SourceColumn = value
    191.             End Set
    192.         End Property
    193.  
    194.         Public Overrides Property SourceVersion() As System.Data.DataRowVersion
    195.             <DebuggerStepThrough()> _
    196.             Get
    197.                 Return m_SourceVersion
    198.             End Get
    199.             <DebuggerStepThrough()> _
    200.             Set(ByVal value As System.Data.DataRowVersion)
    201.                 m_SourceVersion = value
    202.             End Set
    203.         End Property
    204.  
    205.         Public Overrides Property Value() As Object
    206.             <DebuggerStepThrough()> _
    207.             Get
    208.                 Return m_Value
    209.             End Get
    210.             <DebuggerStepThrough()> _
    211.             Set(ByVal value As Object)
    212.                 m_Value = value
    213.             End Set
    214.         End Property
    215.  
    216.         Public Property Precision() As Byte
    217.             <DebuggerStepThrough()> _
    218.             Get
    219.                 Return m_Percision
    220.             End Get
    221.             <DebuggerStepThrough()> _
    222.             Set(ByVal value As Byte)
    223.                 m_Percision = value
    224.             End Set
    225.         End Property
    226.  
    227.         Public Property Scale() As Byte
    228.             <DebuggerStepThrough()> _
    229.             Get
    230.                 Return m_Scale
    231.             End Get
    232.             <DebuggerStepThrough()> _
    233.             Set(ByVal value As Byte)
    234.                 m_Scale = value
    235.             End Set
    236.         End Property
    237.  
    238.         Public Overrides Property Size() As Integer
    239.             <DebuggerStepThrough()> _
    240.             Get
    241.                 Return m_Size
    242.             End Get
    243.             <DebuggerStepThrough()> _
    244.             Set(ByVal value As Integer)
    245.                 m_Size = value
    246.             End Set
    247.         End Property
    248.  
    249.         Public Overrides Sub ResetDbType()
    250.             Return
    251.         End Sub
    252.  
    253.         Public Overrides Property SourceColumnNullMapping() As Boolean
    254.             Get
    255.                 Return m_SourceColumnNullMapping
    256.             End Get
    257.             Set(ByVal value As Boolean)
    258.                 m_SourceColumnNullMapping = value
    259.             End Set
    260.         End Property
    261.  
    262.         Public Function Parameter(ByVal provider As String) As System.Data.Common.DbParameter
    263.             Dim param As System.Data.Common.DbParameter = _
    264.                 System.Data.Common.DbProviderFactories.GetFactory(provider).CreateParameter
    265.  
    266.             With param
    267.                 .DbType = Me.DbType
    268.                 .Direction = Me.Direction
    269.                 .ParameterName = Me.ParameterName
    270.                 .Size = Me.Size
    271.                 .SourceColumn = Me.SourceColumn
    272.                 .SourceColumnNullMapping = Me.SourceColumnNullMapping
    273.                 .SourceVersion = Me.SourceVersion
    274.                 .Value = Me.Value
    275.             End With
    276.             Return param
    277.         End Function
    278.  
    279.     End Class
    280.  
    281. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  5. #5

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    Core namespace classes and code:

    VB Code:
    1. Namespace Core
    2.  
    3.     Public Class CSSIDbParameterCollection
    4.         Implements Collections.Generic.IList(Of Core.CSSIDbParameter)
    5.  
    6.         Private m_Collection As List(Of Core.CSSIDbParameter)
    7.  
    8.         <DebuggerStepThrough()> _
    9.         Public Sub New()
    10.             m_Collection = New List(Of Core.CSSIDbParameter)
    11.         End Sub
    12.  
    13.         <DebuggerStepThrough()> _
    14.         Public Sub Add(ByVal item As Core.CSSIDbParameter) Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).Add
    15.             m_Collection.Add(item)
    16.         End Sub
    17.  
    18.         Public Sub Clear() Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).Clear
    19.             m_Collection.Clear()
    20.         End Sub
    21.  
    22.         Public Function Contains(ByVal item As Core.CSSIDbParameter) As Boolean Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).Contains
    23.             Return m_Collection.Contains(item)
    24.         End Function
    25.  
    26.         Public Sub CopyTo(ByVal array() As Core.CSSIDbParameter, ByVal arrayIndex As Integer) Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).CopyTo
    27.             m_Collection.CopyTo(array, arrayIndex)
    28.         End Sub
    29.  
    30.         Public ReadOnly Property Count() As Integer Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).Count
    31.             Get
    32.                 Return m_Collection.Count
    33.             End Get
    34.         End Property
    35.  
    36.         Public ReadOnly Property IsReadOnly() As Boolean Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).IsReadOnly
    37.             Get
    38.                 Return False
    39.             End Get
    40.         End Property
    41.  
    42.         Public Function Remove(ByVal item As Core.CSSIDbParameter) As Boolean Implements System.Collections.Generic.ICollection(Of Core.CSSIDbParameter).Remove
    43.             m_Collection.Remove(item)
    44.         End Function
    45.  
    46.         Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of Core.CSSIDbParameter) Implements System.Collections.Generic.IEnumerable(Of Core.CSSIDbParameter).GetEnumerator
    47.             Return m_Collection.GetEnumerator
    48.         End Function
    49.  
    50.         Public Function IndexOf(ByVal item As Core.CSSIDbParameter) As Integer Implements System.Collections.Generic.IList(Of Core.CSSIDbParameter).IndexOf
    51.             Return m_Collection.IndexOf(item)
    52.         End Function
    53.  
    54.         Public Sub Insert(ByVal index As Integer, ByVal item As Core.CSSIDbParameter) Implements System.Collections.Generic.IList(Of Core.CSSIDbParameter).Insert
    55.             m_Collection.Insert(index, item)
    56.         End Sub
    57.  
    58.         Default Public Property Item(ByVal index As Integer) As Core.CSSIDbParameter Implements System.Collections.Generic.IList(Of Core.CSSIDbParameter).Item
    59.             Get
    60.                 Return m_Collection(index)
    61.             End Get
    62.             Set(ByVal value As Core.CSSIDbParameter)
    63.                 m_Collection(index) = value
    64.             End Set
    65.         End Property
    66.  
    67.         Public Sub RemoveAt(ByVal index As Integer) Implements System.Collections.Generic.IList(Of Core.CSSIDbParameter).RemoveAt
    68.             m_Collection.RemoveAt(index)
    69.         End Sub
    70.  
    71.         Private Function GetEnumerator1() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
    72.             Return Nothing
    73.         End Function
    74.  
    75.         Public Function ContainsSelectParameters() As Boolean
    76.             Return m_Collection.Exists(AddressOf FindSelectParams)
    77.         End Function
    78.  
    79.         Public Function ContainsInsertParameters() As Boolean
    80.             Return m_Collection.Exists(AddressOf FindInsertParams)
    81.         End Function
    82.  
    83.         Public Function ContainsUpdateParameters() As Boolean
    84.             Return m_Collection.Exists(AddressOf FindUpdateParams)
    85.         End Function
    86.  
    87.         Public Function ContainsDeleteParameters() As Boolean
    88.             Return m_Collection.Exists(AddressOf FindDeleteParams)
    89.         End Function
    90.  
    91.         Public Function GetAllParameters() As List(Of Core.CSSIDbParameter)
    92.             Return m_Collection
    93.         End Function
    94.  
    95.         Public Function GetSelectParameters() As List(Of Core.CSSIDbParameter)
    96.             Return m_Collection.FindAll(AddressOf FindSelectParams)
    97.         End Function
    98.  
    99.         Public Function GetInsertParameters() As List(Of Core.CSSIDbParameter)
    100.             Return m_Collection.FindAll(AddressOf FindInsertParams)
    101.         End Function
    102.  
    103.         Public Function GetUpdateParameters() As List(Of Core.CSSIDbParameter)
    104.             Return m_Collection.FindAll(AddressOf FindUpdateParams)
    105.         End Function
    106.  
    107.         Public Function GetDeleteParameters() As List(Of Core.CSSIDbParameter)
    108.             Return m_Collection.FindAll(AddressOf FindDeleteParams)
    109.         End Function
    110.  
    111.         <DebuggerStepThrough()> _
    112.         Public Function GetReturnValueParameter() As Core.CSSIDbParameter
    113.             Return m_Collection.Find(AddressOf FindReturnValueParam)
    114.         End Function
    115.  
    116.         Public Function GetOutputParameters() As List(Of Core.CSSIDbParameter)
    117.             Return m_Collection.FindAll(AddressOf FindOutputParams)
    118.         End Function
    119.  
    120.         Private Function FindSelectParams(ByVal param As Core.CSSIDbParameter) As Boolean
    121.             If param.ParameterUsage = ParameterUsage.Select Then Return True
    122.             Return False
    123.         End Function
    124.  
    125.         Private Function FindInsertParams(ByVal param As Core.CSSIDbParameter) As Boolean
    126.             If param.ParameterUsage = ParameterUsage.Insert Then Return True
    127.             Return False
    128.         End Function
    129.  
    130.         Private Function FindUpdateParams(ByVal param As Core.CSSIDbParameter) As Boolean
    131.             If param.ParameterUsage = ParameterUsage.Update Then Return True
    132.             Return False
    133.         End Function
    134.  
    135.         Private Function FindDeleteParams(ByVal param As Core.CSSIDbParameter) As Boolean
    136.             If param.ParameterUsage = ParameterUsage.Delete Then Return True
    137.             Return False
    138.         End Function
    139.  
    140.         <DebuggerStepThrough()> _
    141.         Private Function FindReturnValueParam(ByVal param As Core.CSSIDbParameter) As Boolean
    142.             If param.Direction = ParameterDirection.ReturnValue Then Return True
    143.             Return False
    144.         End Function
    145.  
    146.         Private Function FindOutputParams(ByVal param As Core.CSSIDbParameter) As Boolean
    147.             If param.Direction = ParameterDirection.Output Then Return True
    148.             Return False
    149.         End Function
    150.  
    151.     End Class
    152.  
    153. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  6. #6

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    The ParameterBuilders class removes the need to worry about setting up the parameters that will be passed to a command object. since this class makes use of the CSSIDbParameter, (which makes it so that you have the method AddWithValue), all that is needed is the name of a parameter and the value it will return the parameter to be placed in the command object within the BaseDateAccessLayer class.

    Core namespace classes and code:
    VB Code:
    1. Imports System.Data
    2. Imports System.Data.Common
    3. Imports System.Text
    4. Namespace Core
    5.  
    6.     Public MustInherit Class ParameterBuilders
    7.  
    8.         Private m_Provider As String
    9.         Private m_RegisterPrefix As String = String.Empty
    10.  
    11.         Public WriteOnly Property RegisterPrefex() As String
    12.             Set(ByVal value As String)
    13.                 m_RegisterPrefix = value
    14.             End Set
    15.         End Property
    16.  
    17.         'Public Shared Function GetBuilders(ByVal provider As String) As ParameterBuilders
    18.         '    Return New ParameterBuilders(provider)
    19.         'End Function
    20.  
    21.         <DebuggerStepThrough()> _
    22.         Protected Sub New(ByVal provider As String)
    23.             m_Provider = provider
    24.         End Sub
    25.  
    26.         Protected Sub New(ByVal provider As String, ByVal prefix As String)
    27.             m_Provider = provider
    28.             m_RegisterPrefix = prefix
    29.         End Sub
    30.  
    31.         <DebuggerStepThrough()> _
    32.         Protected Overridable Function ParameterBuilder(ByVal paramName As String, _
    33.                                          ByVal value As Object, _
    34.                                          Optional ByVal prefix As String = "") _
    35.                                          As Core.CSSIDbParameter
    36.             Dim hash As New Hashtable
    37.  
    38.             hash.Add(paramName, value)
    39.             Return ParameterBuilder(hash, prefix)(0)
    40.         End Function
    41.  
    42.         <DebuggerStepThrough()> _
    43.         Protected Overridable Function ParameterBuilder(ByVal paramNames As String(), _
    44.                                          ByVal values As Object(), _
    45.                                          Optional ByVal prefix As String = "") _
    46.                                          As Core.CSSIDbParameterCollection
    47.             Dim hash As New Hashtable
    48.  
    49.             If paramNames.Length <> values.Length Then
    50.                 Throw New IndexOutOfRangeException("Total number of parameters and total number of values does not match")
    51.             End If
    52.  
    53.             For i As Integer = 0 To paramNames.Length - 1
    54.                 hash.Add(paramNames(i), values(i))
    55.             Next
    56.             Return ParameterBuilder(hash, prefix)
    57.         End Function
    58.  
    59.         <DebuggerStepThrough()> _
    60.         Protected Overridable Function ParameterBuilder(ByVal hash As Hashtable, _
    61.                                          Optional ByVal prefix As String = "") _
    62.                                          As Core.CSSIDbParameterCollection
    63.             If String.IsNullOrEmpty(m_RegisterPrefix) Then
    64.                 If Not String.IsNullOrEmpty(prefix) AndAlso prefix.Length > 1 Then
    65.                     Throw New OverflowException("Prefix cannot be greater then 1")
    66.                 ElseIf Not String.IsNullOrEmpty(prefix) AndAlso prefix.Length = 1 AndAlso Not (prefix = "@" OrElse prefix = "?" OrElse prefix = ":") Then
    67.                     Throw New InvalidExpressionException("Unknown prefix value")
    68.                 End If
    69.             Else
    70.                 prefix = m_RegisterPrefix
    71.             End If
    72.             If hash Is Nothing Then Return Nothing
    73.             Dim paramsArray As New Core.CSSIDbParameterCollection
    74.             Dim paramNames(hash.Count - 1) As String
    75.  
    76.             hash.Keys.CopyTo(paramNames, 0)
    77.             For Each name As String In paramNames
    78.                 With paramsArray
    79.                     Dim obj As Object = DBNull.Value
    80.  
    81.                     If hash(name) IsNot Nothing AndAlso hash(name) IsNot DBNull.Value Then
    82.                         If hash(name).GetType Is GetType(DateTime) AndAlso hash(name) <> Date.MinValue Then
    83.                             obj = hash(name)
    84.                         ElseIf hash(name).GetType IsNot GetType(DateTime) Then
    85.                             obj = hash(name)
    86.                         End If
    87.                     End If
    88.                     Dim param As DbParameter = _
    89.                         DbProviderFactories.GetFactory(m_Provider).CreateParameter
    90.  
    91.                     param.ParameterName = String.Format("{0}{1}", prefix, name)
    92.                     param.Value = obj
    93.                     .Add(New Core.CSSIDbParameter(param.ParameterName, param.Value))
    94.                 End With
    95.             Next
    96.             Return paramsArray
    97.         End Function
    98.  
    99.     End Class
    100.  
    101. End Namespace
    Last edited by vbdotnetboy; Nov 5th, 2007 at 10:08 AM. Reason: requested my mod

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  7. #7

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    AND FINALLY PART 1
    DataLayer namespace classes and code:

    VB Code:
    1. Namespace DataLayer
    2.     'FUTURE IMPLEMENTATION
    3.     Public Class FetchDataEventArgs : Inherits System.EventArgs
    4.  
    5.         Public Sub New()
    6.  
    7.         End Sub
    8.  
    9.     End Class
    10.  
    11. End Namespace
    12.  
    13.  
    14.  
    15. Namespace DataLayer
    16.     'FUTURE IMPLEMENTATION
    17.     Public Class TransmitDataEventArgs : Inherits System.EventArgs
    18.  
    19.         Public Sub New()
    20.  
    21.         End Sub
    22.  
    23.     End Class
    24.  
    25. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  8. #8

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    The Last Bit I'm Posting As A Zip File As I Can't Find A Happy Medium
    This Code Also Needs A Major Refactoring Which I'm Going To Do Someday
    Attached Files Attached Files

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  9. #9

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    EXAMPLE OF HOW IT ALL TIES TOGETHER

    vb Code:
    1. Imports System.Text
    2. Imports CSSI.Library.Data.Core
    3. Imports System.ComponentModel
    4. Imports CSSI.Configuration.ConnectionStringExSectionHandler
    5. Imports CSSI.Configuration.ConnectionStringExSectionHandler.ConnectionStringExSection
    6. Namespace Security.ChallengeQuestion
    7.  
    8.     <Serializable()> _
    9.     Public Class QuestionManager : Inherits CSSI.Library.Data.DataLayer.BaseDataAccessLayer
    10.  
    11.         Public Sub New(ByVal dataProvider As String, ByVal cnnStr As String)
    12.             MyBase.New(dataProvider, cnnStr)
    13.         End Sub
    14.  
    15.         Public Sub New()
    16.             MyBase.New(GetConfig.ConnectionStrings(0).DataProvider, _
    17.                 GetConfig.ConnectionStrings(0).ConnectionString)
    18.         End Sub
    19.  
    20.         <DebuggerStepThrough()> _
    21.         <DataObjectMethod(DataObjectMethodType.Select)> _
    22.         Public Function GetQuestionsList() As List(Of Question)
    23.             Dim list As List(Of Question) = Nothing
    24.             Dim sql As New StringBuilder
    25.             Dim paramHash As New Hashtable
    26.  
    27.             With sql
    28.                 .AppendFormat("SELECT * FROM {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    29.                 .AppendLine()
    30.                 .AppendFormat("WHERE {0}=@{0}", DB_Constants.ChallengeQuestions.ACTIVE)
    31.             End With
    32.  
    33.             With paramHash
    34.                 .Add(DB_Constants.ChallengeQuestions.ACTIVE, 1)
    35.             End With
    36.  
    37.             For Each obj As Object In Me.FetchDataObjects(GetType(Question), sql.ToString, Me.ParameterBuilder(paramHash, "@"), , True)
    38.                 If list Is Nothing Then
    39.                     list = New List(Of Question)
    40.                 End If
    41.                 list.Add(obj)
    42.             Next
    43.             Return list
    44.         End Function
    45.  
    46.         <DebuggerStepThrough()> _
    47.         <DataObjectMethod(DataObjectMethodType.Select)> _
    48.         Public Function GetQuestionsList(ByVal selectedQuestionId As Int32) As List(Of Question)
    49.             Dim list As List(Of Question) = Nothing
    50.             Dim sql As New StringBuilder
    51.             Dim paramHash As New Hashtable
    52.  
    53.             With sql
    54.                 .AppendFormat("SELECT * FROM {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    55.                 .AppendLine()
    56.                 .AppendFormat("WHERE {0}=@{0} AND {1}<>@{1}", _
    57.                     DB_Constants.ChallengeQuestions.ACTIVE, _
    58.                     DB_Constants.ChallengeQuestions.QUESTION_ID)
    59.             End With
    60.  
    61.             With paramHash
    62.                 .Add(DB_Constants.ChallengeQuestions.ACTIVE, 1)
    63.                 .Add(DB_Constants.ChallengeQuestions.QUESTION_ID, selectedQuestionId)
    64.             End With
    65.  
    66.             For Each obj As Object In Me.FetchDataObjects(GetType(Question), sql.ToString, Me.ParameterBuilder(paramHash, "@"), , True)
    67.                 If list Is Nothing Then
    68.                     list = New List(Of Question)
    69.                 End If
    70.                 list.Add(obj)
    71.             Next
    72.             Return list
    73.         End Function
    74.  
    75.         <DebuggerStepThrough()> _
    76.         <DataObjectMethod(DataObjectMethodType.Select)> _
    77.         Public Function GetQuestionsList(ByVal selectedQuestionId1 As Int32, _
    78.                                          ByVal selectedQuestionId2 As Int32) As List(Of Question)
    79.             Dim list As List(Of Question) = Nothing
    80.             Dim sql As New StringBuilder
    81.             Dim paramHash As New Hashtable
    82.  
    83.             With sql
    84.                 .AppendFormat("SELECT * FROM {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    85.                 .AppendLine()
    86.                 .AppendFormat("WHERE {0}=@{0} AND {1}<>@{1}_1 AND {1}<>@{1}_2", _
    87.                     DB_Constants.ChallengeQuestions.ACTIVE, _
    88.                     DB_Constants.ChallengeQuestions.QUESTION_ID)
    89.             End With
    90.  
    91.             With paramHash
    92.                 .Add(DB_Constants.ChallengeQuestions.ACTIVE, 1)
    93.                 .Add(DB_Constants.ChallengeQuestions.QUESTION_ID + "_1", selectedQuestionId1)
    94.                 .Add(DB_Constants.ChallengeQuestions.QUESTION_ID + "_2", selectedQuestionId2)
    95.             End With
    96.  
    97.             For Each obj As Object In Me.FetchDataObjects(GetType(Question), sql.ToString, Me.ParameterBuilder(paramHash, "@"), , True)
    98.                 If list Is Nothing Then
    99.                     list = New List(Of Question)
    100.                 End If
    101.                 list.Add(obj)
    102.             Next
    103.             Return list
    104.         End Function
    105.  
    106.         <DataObjectMethod(DataObjectMethodType.Select)> _
    107.         Public Function GetQuestion(ByVal questionId As Int32) As Question
    108.             Dim quest As Question = Nothing
    109.             Dim sql As New StringBuilder
    110.             Dim paramHash As New Hashtable
    111.  
    112.             With sql
    113.                 .AppendFormat("SELECT * FROM {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    114.                 .AppendLine()
    115.                 .AppendFormat("WHERE {0}=@{0}", DB_Constants.ChallengeQuestions.QUESTION_ID)
    116.             End With
    117.             With paramHash
    118.                 .Add(DB_Constants.ChallengeQuestions.QUESTION_ID, questionId)
    119.             End With
    120.  
    121.             quest = Me.FetchDataObject(GetType(Question), sql.ToString, _
    122.                 Me.ParameterBuilder(paramHash, "@"), , True)
    123.  
    124.             Return quest
    125.         End Function
    126.  
    127.         <DataObjectMethod(DataObjectMethodType.Select)> _
    128.         Public Function GetQuestions() As QuestionTable
    129.             Dim sql As New StringBuilder
    130.             With sql
    131.                 .AppendFormat("SELECT * FROM {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    132.             End With
    133.             Dim tbl As QuestionTable = Me.FetchData(New QuestionTable, sql.ToString, Nothing)
    134.  
    135.             Return tbl
    136.         End Function
    137.  
    138.         <DataObjectMethod(DataObjectMethodType.Update Or DataObjectMethodType.Insert)> _
    139.         Public Function Save(ByVal question As Question) As Int32
    140.             Dim retval As Int32 = -1
    141.             Dim sql As New StringBuilder
    142.             Dim paramHash As New Hashtable
    143.  
    144.             With sql
    145.                 If question.QuestionId < 1 Then
    146.                     .AppendFormat("INSERT INTO {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    147.                     .AppendLine()
    148.                     .AppendFormat("({0},{1},{2}) VALUES(@{0},@{1},@{2})", _
    149.                         DB_Constants.ChallengeQuestions.QUESTION, _
    150.                         DB_Constants.ChallengeQuestions.TYPE, _
    151.                         DB_Constants.ChallengeQuestions.ACTIVE)
    152.                 Else
    153.                     .AppendFormat("UPDATE {0}", DB_Constants.ChallengeQuestions.TABLE_NAME)
    154.                     .AppendLine()
    155.                     .Append("SET")
    156.                     .AppendLine()
    157.                     .AppendFormat("{0}=@{0},{1}=@{1},{2}=@{2}", _
    158.                         DB_Constants.ChallengeQuestions.QUESTION, _
    159.                         DB_Constants.ChallengeQuestions.TYPE, _
    160.                         DB_Constants.ChallengeQuestions.ACTIVE)
    161.                     .AppendLine()
    162.                     .AppendFormat("WHERE {0}=@{0}", DB_Constants.ChallengeQuestions.QUESTION_ID)
    163.                 End If
    164.             End With
    165.             With paramHash
    166.                 If question.QuestionId > 0 Then
    167.                     .Add(DB_Constants.ChallengeQuestions.QUESTION_ID, question.QuestionId)
    168.                 End If
    169.                 .Add(DB_Constants.ChallengeQuestions.QUESTION, question.Question)
    170.                 .Add(DB_Constants.ChallengeQuestions.TYPE, question.Type)
    171.                 .Add(DB_Constants.ChallengeQuestions.ACTIVE, IIf(question.Active, "1", "0"))
    172.             End With
    173.             Dim trx As Common.DbTransaction = Nothing
    174.             retval = Me.TransmitData(sql.ToString, Me.ParameterBuilder(paramHash, "@"), , , True, trx)
    175.  
    176.             If retval = 1 Then
    177.                 trx.Commit()
    178.             Else
    179.                 trx.Rollback()
    180.             End If
    181.             trx.Dispose()
    182.             Return retval
    183.         End Function
    184.  
    185.     End Class
    186.  
    187. End Namespace

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  10. #10

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: SqlClient or DataFactory

    connectionstring configuration section code
    Attached Files Attached Files

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Generic DbProviderFactory Access

    Moved to the CodeBank

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width