G
Guest
I am adding support to my application for Oracle 10g and using Enterprise
Library Data Access Application Blocks and trying to determine the best way
to convert the GUID's which are stored as RAW(16) in Oracle (Byte Arrays)
back to GUID's in my data layer. My best guess is a conversion method that
the DataSet goes through before leaving the data access layer. Here is my
code:
Private Sub Raw16ToGuid(ByRef dataSet As DataSet)
Dim columnIndices As New ArrayList
Dim dataColumn As DataColumn
For Each DataColumn In dataSet.Tables(0).Columns
If dataColumn.DataType Is System.Type.GetType("System.Byte[]")
Then
columnIndices.Add(dataColumn.Ordinal)
End If
Next
Dim dataRow As DataRow
For Each dataRow In dataSet.Tables(0).Rows
Dim index As Integer = 0
For Each index In columnIndices
dataRow(index) = New Guid(DirectCast(dataRow(index), Byte()))
Next
Next
dataSet.AcceptChanges()
End Sub
I know this will attempt to convert any byte array to a GUID but since I
don't use any other byte arrays currently, it seems better than checking each
dataItem for type and length before attempting the conversion. Any feedback
or suggestions would be appreciated.
Library Data Access Application Blocks and trying to determine the best way
to convert the GUID's which are stored as RAW(16) in Oracle (Byte Arrays)
back to GUID's in my data layer. My best guess is a conversion method that
the DataSet goes through before leaving the data access layer. Here is my
code:
Private Sub Raw16ToGuid(ByRef dataSet As DataSet)
Dim columnIndices As New ArrayList
Dim dataColumn As DataColumn
For Each DataColumn In dataSet.Tables(0).Columns
If dataColumn.DataType Is System.Type.GetType("System.Byte[]")
Then
columnIndices.Add(dataColumn.Ordinal)
End If
Next
Dim dataRow As DataRow
For Each dataRow In dataSet.Tables(0).Rows
Dim index As Integer = 0
For Each index In columnIndices
dataRow(index) = New Guid(DirectCast(dataRow(index), Byte()))
Next
Next
dataSet.AcceptChanges()
End Sub
I know this will attempt to convert any byte array to a GUID but since I
don't use any other byte arrays currently, it seems better than checking each
dataItem for type and length before attempting the conversion. Any feedback
or suggestions would be appreciated.