473,545 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByR ef dataSet As DataSet)
Dim columnIndices As New ArrayList
Dim dataColumn As DataColumn
For Each DataColumn In dataSet.Tables( 0).Columns
If dataColumn.Data Type Is System.Type.Get Type("System.By te[]")
Then
columnIndices.A dd(dataColumn.O rdinal)
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.AcceptC hanges()
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 7716
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
invalidcastexce ption. Any suggestions on fixing this issue? I tried changing
the datacolumn.data type 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(ByR ef 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.Data Type Is
System.Type.Get Type("System.By te[]") Then
columnIndices.A dd(dataColumn.O rdinal)
Dim newDataColumn As New
DataColumn(data Column.ColumnNa me, System.Type.Get Type("System.Gu id"))
newDataTable.Co lumns.Add(newDa taColumn)
Else
Dim newDataColumn As New
DataColumn(data Column.ColumnNa me, dataColumn.Data Type)
newDataTable.Co lumns.Add(newDa taColumn)
End If
Next
Dim dataRow As DataRow
For Each dataRow In table.Rows
Dim index As Integer = 0
Dim newDataRow As DataRow = newDataTable.Ne wRow
For Each item As Object In dataRow.ItemArr ay
If columnIndices.C ontains(index) Then
newDataRow(inde x) = New Guid(CType(item ,
Byte())) ' convert guid
Else
newDataRow(inde x) = item
End If
index += 1
Next
newDataTable.Ro ws.Add(newDataR ow)
Next
newDataSet.Tabl es.Add(newDataT able)
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(ByR ef dataSet As DataSet)
Dim columnIndices As New ArrayList
Dim dataColumn As DataColumn
For Each DataColumn In dataSet.Tables( 0).Columns
If dataColumn.Data Type Is System.Type.Get Type("System.By te[]")
Then
columnIndices.A dd(dataColumn.O rdinal)
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.AcceptC hanges()
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
10067
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 but couldn't find a Python specific one. Thanks, Jeff
24
10852
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
3256
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 need to be visible at the same time so no dropdowns (combo boxes) and no scrolling lists (list boxes). I will use tabbed sheets with logically...
4
5959
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 thrown at it but today during a test, a bracket "}" passed through the method as a valid guid so I wanted to know if this expresion will stop invalid...
1
4077
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
731
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 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...
2
8095
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 message: "Type System.Byte can not be marshaled as an unmanaged structure; no meaningful size or offset can be computed."
0
1694
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 type of the parameter as OleDbType.Guid but it fails with some garbage character ?#4 as the exception message. My query has this end string...
0
3108
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! Here is the code: ======
1
7411
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5965
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1871
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
695
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.