emi_sastra
asked on
Change Data Type from BigInt to UniqueIdentifier. The column is Primary key.
Hi All,
I have a key from BigInt Identity to UniqueIdentifier.
The problem is not all database change, some server are not changed yet.
sbdSQLCommand.AppendLine(" SELECT")
sbdSQLCommand.AppendLine(" ID")
sbdSQLCommand.AppendLine(" FROM TDPOJUAL")
sbdSQLCommand.AppendLine(" WHERE Nomor_OA = @Nomor_OA ")
sbdSQLCommand.AppendLine(" AND BarangCode = @BarangCode ")
cmdSQLCommand.CommandType = CommandType.Text
cmdSQLCommand.CommandText = sbdSQLCommand.ToString
cmdSQLCommand.Parameters.C lear()
cmdSQLCommand.Parameters.A ddWithValu e("@Nomor_ OA", txtNomor_OA.Text)
cmdSQLCommand.Parameters.A ddWithValu e("@Barang Code", dtRow("BarangCode"))
HideKeyTDPOJUAL = cmdSQLCommand.ExecuteScala r()
dtRow("IDDetailSO") = HideKeyTDPOJUAL
The variable HideKeyTDPOJUAL is GUID at the moment.
How could I code it to make it work for both BigInt and UniqueIdentifier ?
Thank you.
I have a key from BigInt Identity to UniqueIdentifier.
The problem is not all database change, some server are not changed yet.
sbdSQLCommand.AppendLine("
sbdSQLCommand.AppendLine("
sbdSQLCommand.AppendLine("
sbdSQLCommand.AppendLine("
sbdSQLCommand.AppendLine("
cmdSQLCommand.CommandType = CommandType.Text
cmdSQLCommand.CommandText = sbdSQLCommand.ToString
cmdSQLCommand.Parameters.C
cmdSQLCommand.Parameters.A
cmdSQLCommand.Parameters.A
HideKeyTDPOJUAL = cmdSQLCommand.ExecuteScala
dtRow("IDDetailSO") = HideKeyTDPOJUAL
The variable HideKeyTDPOJUAL is GUID at the moment.
How could I code it to make it work for both BigInt and UniqueIdentifier ?
Thank you.
ASKER
Hi Stefan,
This application should accommodate for for data type.
What is the solution ?
Thank you.
This application should accommodate for for data type.
What is the solution ?
Thank you.
<StructLayout(LayoutKind.Explicit)> Public Structure GuidOrBigInt
<FieldOffset(0)> Dim GuidVal As GUID
<FieldOffset(0)> Dim BigIntVal As Int64
End Structure
Dim HideKeyTDPOJUAL As GuidOrBigInt
ASKER
Hi Ark,
How to use it?
What should I change from my code ?
Thank you.
How to use it?
What should I change from my code ?
Thank you.
This structure is like C++ union - it accepts either BigInt or GUID. If you pass GUID to this structure (HideKeyTDPOJUAL.GuidVal = Guid.NewGuid) the GuidVal will be this GUID and BigIntVal - first 8 bytes from GUID. If you pass bigint to it - guid will be villed with significant bytes anjd last 8 bytes will be zero (HideKeyTDPOJUAL.BigIntVal = Int64.MaxValue)
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Then this piece of code will work regardless of the data type of the ID column for the retrieving part. Setting it will only work if IDDetailSO has the same data type as ID.
But you need to test obviously agains both data models.