how do i display a decrypted data from dataset into a datagrid? RRS feed

  • Question

  • Hello,
    I have the following segment of code from my project. I want to be able to display decrypted data from dataset which retrieved from a MS SQL database, in a datagrid. my frustration can be seen inthe "for Loop" where i tried many alternatives to get it right but could not.
    Sory if this is not the right forum, I would like to be properly guided on that!
    Please can any one help me get this right.
    Here is the code:

                'datGrid.DataSource = ds.Tables(0)
                'Dim ind As Integer
                Dim dc As DataColumn = New DataColumn
                Dim dRow As DataRow
                dRow = dt.NewRow
                'Dim str As String = Convert.ToString(ds.Tables(0).Rows(1))
                'decryptedTxt.Text = str
                'Dim i As Integer
                'Dim by() As Byte
                ' For Each dRow In ds.Tables("Lab").Rows
                For Each dRow In ds.Tables("Lab").Rows
                    'For Each dc In ds.Tables(0).Columns
                    'If dc.DataType.ToString() = "System.String" Then
                    'If dRow(dc).ToString = "system.Byte" Then
                    decData = New TripleDES()
                    deRecData = decData.Decrypt(dRow.Item("Test_type"))
                    datGrid.DataSource = dr.Item(deRecData)
                    datGrid.DataSource = dr.Item("Patient_ID")
                    datGrid.DataSource = dr.Item("Date_Collected")
                    ' Str = dRow(dc).ToString
                    ' For i = 0 To str.Length - 1
                    'by = Convert.ToByte(str(i))
                    '  Next
                    ' by = Convert.FromBase64String(dRow(dc).ToString)
                    'Dim by() As Byte = StrToByteArray(dRow(dc))
                    'dRow(dc) = decData.Decrypt(by)
                    'deRecData = decData.Decrypt(by)
                    ' End If

    Thanks !

    Sunday, July 19, 2009 12:08 PM

All replies

  • Hi,

    Is your data originally encrypted using SQL Server's cell-level encryption functions (EncryptByKey)?

    In order fto understand why the encrypted data might not decrypt properly, it is important to get a better understanding of the cryptographic cipher text generated by SQL Server.

    More details on the cipherTextMessage can be found here -


    It is strongly recommended to use SQL Server's cell-level decryption functions (DecryptByKey) to decrypt data if the original data was encrypted using encryptByKey.

    Hope this helps!


    Don Pinto, Microsoft, SQL Server Engine. ---------------------------------------------------------- This posting is provided "AS IS" with no warranties, and confers no rights. ---------------------------------------------------------
    Wednesday, December 22, 2010 2:53 AM