Mark C.
Mark C.

Reputation: 6460

Decrypt fields in VB.NET DataSet

I have this working fine in a DataTable, however the DataSet does not have the .Rows property. All fields will not be encrypted, thus they will not all be decrypting. I am assuming it would be some kind of loop, like:

For (i = 0, i < DataSet.ColumnIndex [Or something], i++)

However, I am not sure how to perform this.

Essentially, when I bring back data using a SELECT queries based on input parameters the user enters (first name, last name) I would like to decrypt specific rows.

How I currently use it:

        Try
        For i As Integer = 0 To dt.Rows.Count - 1
            dt.Rows(i)("FIRST_NM_TXT") = clsEncrypt.DecryptData(dt.Rows(i)("FIRST_NM_TXT"))
            dt.Rows(i)("LAST_NM_TXT") = clsEncrypt.DecryptData(dt.Rows(i)("LAST_NM_TXT"))
        Next
    Catch ex As Exception
        MessageBox.Show("Either the first name or last name did not match. Please check your spelling.")
    End Try

The reason I need a DataSet is because I need to run reports off of this decrypted data. I have tried with my DataTable, however I have not been successful. From research, it seems as though DataSet is the common choice anyway.

Upvotes: 0

Views: 670

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27342

A DataSet object is just a collection of DataTable objects

You can access the DataTables in a DataSet by:

Oridinal Dim MyDataTable as DataTable = MyDataSet.Tables(2) or

Name Dim MyDataTable as DataTable = MyDataSet.Tables("Customers")

So just use one of the above methods to decrypt the data once you have the DataSet

For i As Integer = 0 To MyDataTable.Rows.Count - 1
    MyDataTable.Rows(i)("FIRST_NM_TXT") = clsEncrypt.DecryptData(MyDataTable.Rows(i)("FIRST_NM_TXT"))
    MyDataTable.Rows(i)("LAST_NM_TXT") = clsEncrypt.DecryptData(MyDataTable.Rows(i)("LAST_NM_TXT"))
Next

Upvotes: 1

Related Questions