Question

I've done some Googling but can't find anything concrete enough to go forward with, so here I am.

I have date fields that I am running a WHERE clause against, and returning fields based on that. The date fields are encrypted, so I was forced to take an alternative approach.

    Dim aEmpList(dt.Rows.Count, 5) As String
    Try
        lCount = 0
        For i As Integer = 0 To dt.Rows.Count - 1
            If clsEncrypt.DecryptData(dt.Rows(i)(3)) >= 19500101 Then
                aEmpList(lCount, 0) = clsEncrypt.DecryptData(dt.Rows(i)(0))
                aEmpList(lCount, 1) = clsEncrypt.DecryptData(dt.Rows(i)(1))
                aEmpList(lCount, 2) = clsEncrypt.DecryptData(dt.Rows(i)(2))
                aEmpList(lCount, 3) = clsEncrypt.DecryptData(dt.Rows(i)(3))
                aEmpList(lCount, 4) = clsEncrypt.DecryptData(dt.Rows(i)(4))
                lCount = lCount + 1
            End If
        Next
    Catch ex As Exception
        MessageBox.Show(e.ToString())
    End Try

clsEncrypt is an encryption/decryption class.

The fields are Employee First Name, Last Name, and Date of Birth - and they are all encrypted. I am trying to find all Employees born>= 19500101, and return that data as a report.

I created a Structure and put the data as an array into the structure myStructure

'Define a structure to be used as source for data grid view.
Structure mystructure
    Private mDim1 As String
    Private mDim2 As String
    Private mDim3 As String
    Private mDim4 As String
    Private mDim5 As String
    Public Property Dim1() As String
        Get
            Return mDim1
        End Get
        Set(ByVal value As String)
            mDim1 = value
        End Set
    End Property
    Public Property Dim2() As String
        Get
            Return mDim2
        End Get
        Set(ByVal value As String)
            mDim2 = value
        End Set
    End Property
    Public Property Dim3() As String
        Get
            Return mDim3
        End Get
        Set(ByVal value As String)
            mDim3 = value
        End Set
    End Property
    Public Property Dim4() As String
        Get
            Return mDim4
        End Get
        Set(ByVal value As String)
            mDim4 = value
        End Set
    End Property
    Public Property Dim5() As String
        Get
            Return mDim5
        End Get
        Set(ByVal value As String)
            mDim5 = value
        End Set
    End Property
End Structure

I populate the structure to load into a DataGridView for visualization purposes:

    'populate structure with aEmpList array
    Dim myarr(dt.Rows.Count) As mystructure
    Try
        For i As Integer = 0 To lCount - 1
            myarr(i) = New mystructure With {.Dim1 = aEmpList(i, 0).ToString, .Dim2 = aEmpList(i, 1).ToString, .Dim3 = aEmpList(i, 2).ToString, .Dim4 = aEmpList(i, 3).ToString, .Dim5 = aEmpList(i, 4).ToString}
        Next
    Catch ex As Exception
        MessageBox.Show(e.ToString())
    End Try
DataGridView1.DataSource = myarr

Now that I've provided sufficient background, does anyone know what my next move should be? I'm not sure how, or if, I should load the structure into a DataSet() [if that's even possible] or something of that nature.

Was it helpful?

Solution 2

So, this kind of sucked to figure out, but I got it. As the question title says - I actually ditched the array portion because all it did was confuse me, and I went with the following solution:

    Dim dt As New DataTable
    Dim dts As DataSet = New DataSet()
    With comm
        .CommandText = "SELECT EMPL_ID, EMPL_FIRST_NM, EMPL_LAST_NM, BEG_DT, END_DT FROM EMPL"
    End With

    Dim adapter As New SqlDataAdapter(comm)
    adapter.Fill(dts)                    'Fill DT with Query results

    dt.Load(dts.CreateDataReader())

    Me.reportViewer1.RefreshReport()
    Dim dts2 As New DataSet()

    dts2 = dts.Clone
    Try
        Dim m As Integer
        m = 0
        For i As Integer = 0 To dts.Tables(0).Rows.Count - 1
            If clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(3)) >= "20130101" Then
                dts2.Tables(0).Rows.Add()
                dts2.Tables(0).Rows(m)(0) = clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(0))
                dts2.Tables(0).Rows(m)(1) = clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(1))
                dts2.Tables(0).Rows(m)(2) = clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(2))
                dts2.Tables(0).Rows(m)(3) = clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(3))
                dts2.Tables(0).Rows(m)(4) = clsEncrypt.DecryptData(dts.Tables(0).Rows(i)(4))
                'dts2.Tables(0).Rows.Add(dts.Tables(0).Rows(i).cl)
                m = m + 1
            End If
        Next
    Catch ex As Exception
        MessageBox.Show(e.ToString())
    End Try

    Dim rds As ReportDataSource = New ReportDataSource("DataSetDateOfBirthTest", dts2.Tables(0))
    With reportViewer1
        .LocalReport.DataSources.Clear()
        .LocalReport.DataSources.Add(rds)
        .RefreshReport()
    End With

OTHER TIPS

As I see it you're trying to create a business class, and thus should use a reference type (Class) instead of a value type (Structure). So, the "next move" would be to change your structure to a class, implement INotifyPropertyChanged, IEditableObject, IChangeTracking, IRevertibleChangeTracking, and create a BindingList(Of T) to hold your items.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top