Link to home
Start Free TrialLog in
Avatar of emi_sastra
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.Clear()

                cmdSQLCommand.Parameters.AddWithValue("@Nomor_OA", txtNomor_OA.Text)
                cmdSQLCommand.Parameters.AddWithValue("@BarangCode", dtRow("BarangCode"))

                HideKeyTDPOJUAL = cmdSQLCommand.ExecuteScalar()

                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.
Avatar of ste5an
ste5an
Flag of Germany image

If understand your question correctly:

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.
Avatar of emi_sastra
emi_sastra

ASKER

Hi Stefan,

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

Open in new window

Hi Ark,

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 TRIAL
Members 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.