472,959 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 software developers and data experts.

Best Conversion Method? - Oracle Raw(16) to Sql Guid

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.
Aug 16 '05 #1
1 7576
I started using this and found a problem. The data in the datarows is
converted but the datacolumn datatype stays as a byte array. If the dataset
is serialized for any reason (remoting was mine), there is an
invalidcastexception. Any suggestions on fixing this issue? I tried changing
the datacolumn.datatype but got an error that it can't be changed after the
dataset is created. In the mean time, I rewrote the function as follows:

Private Function Raw16ToGuid(ByRef dataSet As DataSet) As DataSet
' Creates a new dataset with GUID column and converted datatype
in place of byte arrays
Dim table As DataTable
Dim newDataSet As New DataSet
For Each table In dataSet.Tables
Dim newDataTable As New DataTable(table.TableName)
Dim columnIndices As New ArrayList
Dim dataColumn As DataColumn
For Each dataColumn In table.Columns
If dataColumn.DataType Is
System.Type.GetType("System.Byte[]") Then
columnIndices.Add(dataColumn.Ordinal)
Dim newDataColumn As New
DataColumn(dataColumn.ColumnName, System.Type.GetType("System.Guid"))
newDataTable.Columns.Add(newDataColumn)
Else
Dim newDataColumn As New
DataColumn(dataColumn.ColumnName, dataColumn.DataType)
newDataTable.Columns.Add(newDataColumn)
End If
Next
Dim dataRow As DataRow
For Each dataRow In table.Rows
Dim index As Integer = 0
Dim newDataRow As DataRow = newDataTable.NewRow
For Each item As Object In dataRow.ItemArray
If columnIndices.Contains(index) Then
newDataRow(index) = New Guid(CType(item,
Byte())) ' convert guid
Else
newDataRow(index) = item
End If
index += 1
Next
newDataTable.Rows.Add(newDataRow)
Next
newDataSet.Tables.Add(newDataTable)
Next
Return newDataSet
End Function

This creates a new dataset with the row translated. I am sure this is less
efficient but I can't find a way to cleanly translate the datatype in place.
Thanks for any feedback.
"Jim Shank" wrote:
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.

Sep 7 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Jeff Wagner | last post by:
Is there a Python module or method that can convert between numeric bases? Specifically, I need to convert between Hex, Decimal and Binary such as 5Ah = 90d = 01011010b. I searched many places...
24
by: Ilija_G | last post by:
Hi, Is there any replace for "Select @@identity" that could return "just inserted" GUID as a primary key? Has anyone tested what's faster, working with Guid or Autonumber ?
9
by: Frances | last post by:
Hi All, * PREMISE * I'm creating an Access form with 150 items subdivided into 20 categories. Multiple categories (and items) can be selected so my user wants checkboxes. All of the options...
4
by: Greg Merideth | last post by:
I came up with this to test strings passed into a checking method to see if the guid being passed in (regular 128 bit windows registry GUID) is valid. So far it seems to handle most errors...
1
by: Arjen | last post by:
Hi, I have a Guid value. I want to save this inside the memory. What is the best way: save it as a Guid? Or as string? Thanks!
1
by: Jim Shank | last post by:
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...
2
by: john.gillespie | last post by:
I am trying to insert a byte array into an Oracle DB. The type of the column in the DB is Raw The C# type I have is a 16 byte byte array. Whenever I try to do this I get the following error...
0
by: sjoshi | last post by:
Hello All I'm using OraOLEDB.Oracle provider for accessing Oracle. Now I have a column of GUID type that is stored as RAW in Oracle. How do I pass value/type for that parameter. ?? I was using the...
0
by: MarcoDieleman | last post by:
Hello you all, I have this code that is written in MS Transact-SQL and I need to convert it to work with Oracle. Can anyone please help??? I need the code for a VBscript project. Thanks! ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.