473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 7680
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! ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.