Solved

URGENT(!): Advanced (?!) structures manipulating in VB.NET

Posted on 2004-10-02
11
308 Views
Last Modified: 2010-04-23
Hi,

   I'm new to VB.NET. I'm trying to build a data layer for my application. For each table I create a new class (following is an example). For each field in the table a structure is built with the needed functionality. I also build a structure for the table's row (in order to uses it as an argument when calling one of the functions in the data layer).

  My problem is with the functions creation. I'm trying to buid a generic / template function (since the tables can be change and since I want to use the same functions for all of my tables without needing to rewrite them - or with minimum modifications). I want my function to do as follows:

For Each Field In <the given structure>  (SelectCriteria.GetType.GetFields?!)
   If Field.isSelected() Then
      Select Case Field.GetFieldTypeName()
          Case "String"
                    SQLQuery &= " and " & Field.name & " = '" & Field.GetFieldValue() & "' "
          Case "Short"
                    SQLQuery &= " and " & Field.name & " = " & Field.GetFieldValue() & " "
          Case "Nothing"
                    SQLQuery &= " and " & Field.name & " IS NULL "
      End Select
   End If
Next

  I couldn't find eval() or exec() in VB.NET. Can anyone help me with how to do in VB.NET?

Thanks ahead!

--- Q. End ---

--- Example Class Begins Here ---

Public Class UsersTable

#Region "Internal structures definitions"
    Public Structure _USER_ID
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 38 ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _SYSTEM_CREATION_DATE
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _SYSTEM_UPDATE_DATE
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _CREATOR_USER_ID
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 38 ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _OPERATOR_USER_ID
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 38 ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _CREATOR_APPLICATION_ID
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 38 ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _UPDATE_APPLICATION_ID
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 38 ' {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_PROFILE_DELETED_INDICATOR
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 1
        Private fieldSelectedIndicator As Boolean
        Private value As Boolean
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As Boolean
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_EFFECTIVE_DATE
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_EXPIRATION_DATE
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_SHORT_NAME
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 20
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_FIRST_NAME
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Short = 256
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_MIDDLE_NAME
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Short = 256
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LAST_NAME
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Short = 256
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_DESCRIPTION
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Short = 256
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_PASSWORD
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 32
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_PASSWORD_EXPIRATION_DATE
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LOGIN
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 1
        Private fieldSelectedIndicator As Boolean
        Private value As Boolean
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As Boolean
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_FAILED_LOGIN_ATTEMPTS_COUNTER
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 0
        Private fieldSelectedIndicator As Boolean
        Private value As Short
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As Short
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As Short)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As Short)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LOCKED
        Public Const isNullable As Boolean = False
        Public Const maximumLength As Byte = 1
        Private fieldSelectedIndicator As Boolean
        Private value As Boolean
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As Boolean
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As Boolean)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LAST_LOGIN_DATE
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LAST_ACTIVITY_DATE_TIME_STAMP
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 19 ' dd/mm/yyyy tt:MM:ss
        Private fieldSelectedIndicator As Boolean
        Private value As DateTime
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As DateTime
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As DateTime)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LAST_IP
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 15 ' nnn.nnn.nnn.nnn
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_LAST_SESSION_ID
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 15
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_CURRENT_IP
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 15
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
    Public Structure _USER_CURRENT_SESSION_ID
        Public Const isNullable As Boolean = True
        Public Const maximumLength As Byte = 15
        Private fieldSelectedIndicator As Boolean
        Private value As String
        Private valueChangedIndicator As Boolean
        Public Sub DeselectField()
            Me.fieldSelectedIndicator = False
        End Sub
        Public Function GetFieldTypeName() As String
            Return TypeName(Me.value)
        End Function
        Public Function GetFieldValue() As String
            Return Me.value
        End Function
        Public Sub InitilizeFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = False
        End Sub
        Public Function isChanged() As Boolean
            Return Me.valueChangedIndicator
        End Function
        Public Function isSelected() As Boolean
            Return Me.fieldSelectedIndicator
        End Function
        Public Sub SelectField()
            Me.fieldSelectedIndicator = True
        End Sub
        Public Sub SetFieldValue(ByVal value As String)
            Me.value = value
            Me.valueChangedIndicator = True
        End Sub
    End Structure
#End Region

#Region "Row structure definition"
    Public Structure UserRow
        Public USER_ID As _USER_ID
        Public SYSTEM_CREATION_DATE As _SYSTEM_CREATION_DATE
        Public SYSTEM_UPDATE_DATE As _SYSTEM_UPDATE_DATE
        Public CREATOR_USER_ID As _CREATOR_USER_ID
        Public OPERATOR_USER_ID As _OPERATOR_USER_ID
        Public CREATOR_APPLICATION_ID As _CREATOR_APPLICATION_ID
        Public UPDATE_APPLICATION_ID As _UPDATE_APPLICATION_ID
        Public USER_PROFILE_DELETED_INDICATOR As _USER_PROFILE_DELETED_INDICATOR
        Public USER_EFFECTIVE_DATE As _USER_EFFECTIVE_DATE
        Public USER_EXPIRATION_DATE As _USER_EXPIRATION_DATE
        Public USER_SHORT_NAME As _USER_SHORT_NAME
        Public USER_FIRST_NAME As _USER_FIRST_NAME
        Public USER_MIDDLE_NAME As _USER_MIDDLE_NAME
        Public USER_LAST_NAME As _USER_LAST_NAME
        Public USER_DESCRIPTION As _USER_DESCRIPTION
        Public USER_PASSWORD As _USER_PASSWORD
        Public USER_PASSWORD_EXPIRATION_DATE As _USER_PASSWORD_EXPIRATION_DATE
        Public USER_LOGIN As _USER_LOGIN
        Public USER_FAILED_LOGIN_ATTEMPTS_COUNTER As _USER_FAILED_LOGIN_ATTEMPTS_COUNTER
        Public USER_LOCKED As _USER_LOCKED
        Public USER_LAST_LOGIN_DATE As _USER_LAST_LOGIN_DATE
        Public USER_LAST_ACTIVITY_DATE_TIME_STAMP As _USER_LAST_ACTIVITY_DATE_TIME_STAMP
        Public USER_LAST_IP As _USER_LAST_IP
        Public USER_LAST_SESSION_ID As _USER_LAST_SESSION_ID
        Public USER_CURRENT_IP As _USER_CURRENT_IP
        Public USER_CURRENT_SESSION_ID As _USER_CURRENT_SESSION_ID
    End Structure
#End Region

#Region "Functions definitons"
    Public Function SelectUsersTable(ByVal SelectCriteria As UserRow) As OleDb.OleDbCommand
        Dim SQLQuery As String = "select * from USERS where "
        If SelectCriteria.USER_ID.isSelected() Then
            If SelectCriteria.USER_ID.GetFieldValue Is Nothing Then
                SQLQuery &= "USER_ID IS NULL"
            Else
                SQLQuery &= "USER_ID = '" & SelectCriteria.USER_ID.GetFieldValue & "'"
            End If
        End If
        MsgBox(SQLQuery)
    End Function
#End Region
End Class

--- Example Class Ends Here ---

Thanks again !!!
0
Comment
Question by:idoek
  • 5
  • 2
11 Comments
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12208124
you can test

dim c as sqlconnection = new sqlconnection(...)
dim cmd as sqlcommand = new sqlcommand()
c.Open()
cmd.Connection = c

cmd.CommandText = '<------insert/delete type sql
cmd.executenonquery()

cmd.CommandText = '<------select type sql
SqlDataReader myReader =cmd.ExecuteReader()
while(myReader.Read())
      Console.WriteLine(myReader.GetString(0))
end while
myReader.Close()


0
 

Author Comment

by:idoek
ID: 12208203
I'm sorry but this is not what I am looking for ... my question is:

I'm trying to buid a generic / template function (since the tables can be change and since I want to use the same functions for all of my tables without needing to rewrite them - or with minimum modifications AND I WANT IT TO WORK WITH MY STRUCTURES - KNOWING THAT THE STRUCTURE CAN BE CHANGE). I want my function to do as follows:

For Each Field In <the given structure>  (SelectCriteria.GetType.GetFields?!)
   If Field.isSelected() Then
      Select Case Field.GetFieldTypeName()
          Case "String"
                    SQLQuery &= " and " & Field.name & " = '" & Field.GetFieldValue() & "' "
          Case "Short"
                    SQLQuery &= " and " & Field.name & " = " & Field.GetFieldValue() & " "
          Case "Nothing"
                    SQLQuery &= " and " & Field.name & " IS NULL "
      End Select
   End If
Next

Thanks for your quick reply!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12209333
take a look at the Reflection namespace.  Reflection is the process of discovering, at runtime, the properties and methods of an object.

AW
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 500 total points
ID: 12209345
I would also recommend to you, the Book

Expert One on One Visual Basic .NET Business Objects

Rockford Lhotka
APress
ISBN: 1861007264

His book may answer ALL of your questions, and may in fact greatly simplfy what you have created here.

AW
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:idoek
ID: 12211126
Hi Arthur,

   Thanks for your quick comment. I ordered the book from Amazon today. I hope to find the answer there. Meanwhile (it will take it more than 14 days to arrive) if anyone have an idea of how to do it - PLEASE advise!

Thanks again!!!
0
 

Author Comment

by:idoek
ID: 12218035
Hi all,

    I'm rephrasing my question. I need a solution for the following problem: I need a function or subroutine (in VB.NET) that gets an unknown class or structure as an input and scan it. The function (or sub) will be able to give me information about the class (or structure) elements and will be able to work and address each element. For example if it is a String get its value or set a value.

Is it doable? Did anypne ever came across such a function (in VB.NET)?

THANKS AHEAD !!!!!
0
 

Author Comment

by:idoek
ID: 12237071
Well after reading more than 100 articles on the web... the solution is:

    Public Sub SelectUsersTable(ByRef myStructure As Object)

        Dim santaLittleHelperA As FieldInfo
        Dim santaLittleHelperB As FieldInfo
        Dim myInsideField As Object
        For Each santaLittleHelperA In myStructure.GetType().GetFields()
            santaLittleHelperB = myStructure.GetType().GetField(santaLittleHelperA.Name)
            myInsideField = santaLittleHelperB.GetValue(myStructure)
            If myInsideField.isSelected() Then ' working with the an known functionality of an unknown structure (see above)
                ...
            End If
        Next
        ...
End Sub

My NEW problem is: When I set the value of one of the internal "fields" it is changed only inside of the subroutine and not outside (and I'm passing it byRef). Does anyone knows why?! any idea on what is needed to be fix? (the right and working solution will get 500 points!!! PLEASE?! Don't tell me it is to hard for you guy ;o) )
0
 

Author Comment

by:idoek
ID: 12240397
Yep My bad,

You cannot box/unbox a structure ... UserRow needs to be change to class and now with the following code everything is working:

    Public Sub mySubChangeUSERID(ByRef inputClass As Object)
        Dim ClassFieldScanner As Object
        Dim ClassField As Object
        For Each ClassFieldScanner In inputClass.GetType().GetFields()
            ClassField = SelectCriteria.GetType().GetField(ClassFieldScanner.Name).GetValue(inputClass)
            If ClassFieldScanner.Name = "USER_ID" Then
                ClassField.SetFieldValue("My NEW value")
                inputClass.GetType().GetField(ClassFieldScanner.Name).SetValue(inputClass, ClassField)
            End If
        Next
End Function

Now that I answer all my questions ... thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now