Change Data Type from BigInt to UniqueIdentifier. The column is Primary key.

emi_sastra used Ask the Experts™
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("FROM TDPOJUAL")
                sbdSQLCommand.AppendLine("WHERE Nomor_OA = @Nomor_OA ")
                sbdSQLCommand.AppendLine("AND BarangCode = @BarangCode ")

                cmdSQLCommand.CommandType = CommandType.Text
                cmdSQLCommand.CommandText = sbdSQLCommand.ToString


                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.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

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.


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)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial