?
Solved

Set Public Properties from values stored in a DataSet

Posted on 2011-10-26
3
Medium Priority
?
189 Views
Last Modified: 2012-05-12
Experts,

I have a DataGridView that has a set of Public Properties which directly relate to the database connection properties.  I created a series of subroutines that take the Public Properties and create a dataset which I then store as XML.

I just created a load Function that loads the DataSet from the file into dsProperties.  This DataSet has one table "Properties" with four columns; 1) PropertyName, 2) PropertyVariable, 3) PropertyType, and 4) PropertyValue.

I want to loop through the dataset reading the PropertyVariable and match it to the Public Propeties I now have and Set their values to PropertyValue from the DataSet DataTable.

I included the Button_FormSave subroutine which shows you what Subroutines and Functions I call to create the DataSet which is stored to the XML file.  Using this as somewhat of a template I want to be able to match the value of PropertyVariable and set the value to PropertyValue based upon PropertyType.

The PropertyVariables are stored in a database as you'll note.  The values for PropertyVariable are:

        strVarDataSourceLink.p_sDateAdded = Me.TextBox_DateAdded.Text
        strVarDataSourceLink.p_sDateModified = Me.TextBox_DateModified.Text
        strVarDataSourceLink.p_iCodeSequence = 1
        strVarDataSourceLink.p_sRecordStatus = "ACTIVE"
        strVarDataSourceLink.p_sDataSourceName = Me.TextBox_DataSourceLinkName.Text
        strVarDataSourceLink.p_iDatabaseType
        strVarDataSourceLink.p_bLockProperties
        strVarDataSourceLink.p_sConnectionMethod
        strVarDataSourceLink.p_sConnectionType
        strVarDataSourceLink.p_sServerName
        strVarDataSourceLink.p_sServerInstance
        strVarDataSourceLink.p_sDatabaseFolder
        strVarDataSourceLink.p_sDatabaseName
        strVarDataSourceLink.p_sTableName


I decided to use a database table to store the properties as a way to make the process modular so I can use it with other applications I am working on.

So the SetValue is where I need the assistance.  Could you look at the code I have and help me create the Subroutines and Functions to take the DataSet information and populate Public Properties.

I would really appreciate the assistance!
Private Sub Button_FormSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_FormSave.Click

        Dim sFile As String = Me.TextBox_ProjectFilename.Text.Trim
        Dim sFolder As String = Me.TextBox_ProjectFolder.Text.Trim
        Dim bRsp As Boolean = False
        Me.Button_FormLoad.Enabled = False
        Me.Button_FormSave.Enabled = False
        Call subSetupFileStructure_SaveProperties()
        dsProperties = o_clsDataSourceLinkBuilder_DataSet.fncSetupDataSet_Initialize(dsProperties)
        dsProperties = o_clsDataSourceLinkBuilder_DataSet.fncSetupDataSet_AddColumns(dsProperties)
        dsProperties = o_clsDataSourceLinkBuilder_DataSet.fncSetupDataSet_AddProperties(dsProperties)
        dsProperties = o_clsDataSourceLinkBuilder_DataSet.fncSetupDataSet_GetValues(dsProperties, strVarDataSourceLink)
        bRsp = o_clsDataSourceLinkBuilder_XMLFile.fncXMLDataFile_DataSetSave(dsProperties, sFolder, sFile)
        Me.Button_FormLoad.Enabled = True
        Me.Button_FormSave.Enabled = True

    End Sub

    Public Function fncSetupDataSet_Initialize _
           ( _
            ByRef dsDataSet As DataSet _
           ) _
            As DataSet

        Dim sName As String = Nothing
        Dim dtTable As DataTable = New DataTable("Properties")
        Dim iLoop As Integer = 0
        If dsDataSet.Tables.Count > 0 Then
            For iLoop = 1 To dsDataSet.Tables.Count - 1
                sName = dsDataSet.Tables(iLoop - 1).TableName
                dsDataSet.Tables.Remove(sName)
            Next iLoop
        End If
        dsDataSet.Tables.Add("Properties")
        dsDataSet.DataSetName = "Structure"
        Return dsDataSet

    End Function

    Public Function fncSetupDataSet_AddColumns _
           ( _
            ByRef dsDataSet As DataSet _
           ) _
            As DataSet

        Dim dtTables As DataTable = New DataTable
        Dim dtCol0Prop As DataColumn = New DataColumn("PropertyName")
        Dim dtCol1Prop As DataColumn = New DataColumn("PropertyVariable")
        Dim dtCol2Prop As DataColumn = New DataColumn("PropertyType")
        Dim dtCol3Prop As DataColumn = New DataColumn("PropertyValue")
        Dim sTblName As String = Nothing
        Dim iReference As Integer = 0
        Dim iLoop As Integer = 0
        dtTables = oDAL_DBTables.fncGetDataSetPropertiesSelect("DataSourceLink", "TABLES")
        For iLoop = 1 To dtTables.Rows.Count
            iReference = CInt(dtTables.Rows(iLoop - 1).Item("XMLStructure_CodeSequence"))
            sTblName = CStr(dtTables.Rows(iLoop - 1).Item("XMLStructure_TableName"))
            dsDataSet.Tables(sTblName).Columns.Add("PropertyName")
            dsDataSet.Tables(sTblName).Columns.Add("PropertyVariable")
            dsDataSet.Tables(sTblName).Columns.Add("PropertyType")
            dsDataSet.Tables(sTblName).Columns.Add("PropertyValue")
        Next iLoop
        Return dsDataSet

    End Function

    Public Function fncSetupDataSet_AddProperties _
           ( _
            ByRef dsDataSet As DataSet _
           ) _
            As DataSet

        Dim dtTables As DataTable = New DataTable
        Dim dtColumns As DataTable = New DataTable
        Dim oRow As DataRow
        Dim sTblName As String = Nothing
        Dim iReference As Integer = 0
        Dim iLoop As Integer = 0
        Dim iCol As Integer = 0
        dtTables = oDAL_DBTables.fncGetDataSetPropertiesSelect("DataSourceLink", "TABLES")
        For iLoop = 1 To dtTables.Rows.Count
            iReference = CInt(dtTables.Rows(iLoop - 1).Item("XMLStructure_CodeSequence"))
            sTblName = CStr(dtTables.Rows(iLoop - 1).Item("XMLStructure_TableName"))
            dtColumns = oDAL_DBTables.fncGetDataSetPropertiesSelect("DataSourceLink", "COLUMNS", iReference)
            For iCol = 1 To dtColumns.Rows.Count
                oRow = dsDataSet.Tables(sTblName).NewRow
                oRow.Item("PropertyName") = CStr(dtColumns.Rows(iCol - 1).Item("XMLStructure_TablePropertyName"))
                oRow.Item("PropertyVariable") = CStr(dtColumns.Rows(iCol - 1).Item("XMLStructure_FieldVariable"))
                oRow.Item("PropertyType") = CStr(dtColumns.Rows(iCol - 1).Item("XMLStructure_FieldType"))
                oRow.Item("PropertyValue") = Nothing
                dsDataSet.Tables(sTblName).Rows.Add(oRow)
            Next iCol
        Next iLoop
        Return dsDataSet

    End Function

    Public Function fncSetupDataSet_GetValues _
           ( _
            ByRef dsDataSet As DataSet, _
            ByRef strVarDataSourceLink As clsProp_ProjectStructure.subCls_ProjectStructureDataSourceLink _
           ) _
            As DataSet

        Dim sField As String = Nothing
        Dim sValue As String = Nothing
        For iLoop As Integer = 0 To dsDataSet.Tables("Properties").Rows.Count - 1
            sField = CStr(dsDataSet.Tables("Properties").Rows(iLoop).Item("PropertyVariable"))
            sValue = fncSetupDataSet_GetPropertyInformation(dsDataSet, sField, strVarDataSourceLink)
            dsDataSet.Tables("Properties").Rows(iLoop).Item("PropertyValue") = sValue
        Next iLoop
        Return dsDataSet

    End Function

    Private Function fncSetupDataSet_GetPropertyInformation _
            ( _
            ByRef dsDataSet As DataSet, _
            ByVal sField As String, _
            ByRef strVarDataSourceLink As clsProp_ProjectStructure.subCls_ProjectStructureDataSourceLink _
            ) _
             As String

        Dim o_pType As Type = strVarDataSourceLink.GetType
        Dim sFieldName As String = Nothing
        Dim o_pValue As Object = Nothing
        fncSetupDataSet_GetPropertyInformation = Nothing
        For Each pi As PropertyInfo In o_pType.GetProperties
            Debug.Print(pi.Name)
        Next
        Return fncSetupDataSet_GetPropertyInformation

    End Function

Open in new window

0
Comment
Question by:Peter Allen
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37034140
0
 

Author Comment

by:Peter Allen
ID: 37056505
CodeCruiser,

C# doesn't help, sorry.  The VBHelper site was one I looked at originally.  I got the code that you see based partially on this site and another which actually worked better.  I want to reverse the process of GetValue with SetValue.

Can you show me an example and explain it a bit more then what I read in the texts.  It is a bit confusing to me.  That's why sometimes I prefer to follow a good example to break down what is happening.

Thanks!
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1400 total points
ID: 37057581
There is a SetValue function same as GetValue

http://msdn.microsoft.com/en-us/library/xb5dd1f1.aspx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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