So, I'm not sure of the DataRow approach because I wasn't sure how to use it. It's partially my fault because I forgot to mention in my OP that I will need to actually be able to use this data, whether it be for a report or showing data in DGV.
That being said, I found code that led me to use a Structure
. I've never used one before, so this could be entirely wrong - but it works.
'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
Now that we have the structure ready to accept the values we pass into it..
Dim lCount As Integer = 0
Dim dt As New DataTable
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(dt) 'Fill DT with Query results
'read through dataset and write records that meet date criteria to array
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)) >= 20130101 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
'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
'use myarr structure as source for datagridview
DataGridView1.DataSource = myarr 'fill DGV
It's lengthy, and kind of messy, but it works.
In sum, I have encrypted fields within a SQL Server 2008 R2 database. I am trying to bring back records using a SELECT * FROM Table WHERE DATE >= 20130101
(just for examples' sake). Well, when the date fields are encrypted, it's not possible to pass a WHERE
clause and return data. So I had to bring it back, decrypt it, and store it in a data table. I then created an array aEmpList
, and filled it with the decrypted data fields. I finally loaded the structure with datatable decrypted aEmpList
array and used it as the DataSource for a DGV.
Hoepfully someone can find this useful.