473,386 Members | 1,835 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,386 software developers and data experts.

Guid questions

I would like to use a Guid as a record identifier for to prevent update
collisions (not as the key, but as a substitute for a timestamp field).

What is the proper way to define storage for a guid in VB?

What is the proper way to define storage for a guid in SQL Server?

Thanks,

Dean Slindee
Nov 21 '05 #1
4 1565

"Dean Slindee" <sl*****@charter.net> wrote in message
news:fp*******************@fe04.lga...
I would like to use a Guid as a record identifier for to prevent update
collisions (not as the key, but as a substitute for a timestamp field).

What is the proper way to define storage for a guid in VB?

What is the proper way to define storage for a guid in SQL Server?

Thanks,

Dean Slindee

VB.Net:
Dim guidId As Guid = Guid.NewGuid()

I believe in SQL Server, you define a GUID column as Timestamp. If that is
not it, then it most likely is the Image data type...one or the other should
work for you :)

Also, if you want SQL Server to create it for you, you can use the Timestamp
data type and set the Allows Null to false.

Snip:

Dim guidId As Byte() = RowThatContainsGuidId.GuidId

guidId would then contain your Guid...I'm not sure if .Net's Guid is the
same as SQL Server's timestamp column <shrug> something to learn I guess :)

Mythran

Nov 21 '05 #2
SQL 2000 has a "uniqueidentifier" as a datatype. This is basically a guid.
However, you can use the TIMESTAMP type to test for update collisions in
your table.

As GUIDS are just random 128 bit numbers, so there is no "time relation"
between one GUID and another. This makes them very slow as primary keys for
things like inserts but they are essential for replication, so including a
"uniqueidentifier" field in your tables is generally a good idea.
"Dean Slindee" <sl*****@charter.net> wrote in message
news:fp*******************@fe04.lga...
I would like to use a Guid as a record identifier for to prevent update
collisions (not as the key, but as a substitute for a timestamp field).

What is the proper way to define storage for a guid in VB?

What is the proper way to define storage for a guid in SQL Server?

Thanks,

Dean Slindee

Nov 21 '05 #3
Hi,

In addition to the other comments. To create a new guid you can
use guid.newguid.

http://msdn.microsoft.com/library/de...wguidtopic.asp

If adding the record from a stored procedure you can use the sql server
newid function. Field must be of the uniqueidentifier type.

http://msdn.microsoft.com/library/de...a-nop_4pt0.asp

Ken
------------------------------

"Dean Slindee" wrote:
I would like to use a Guid as a record identifier for to prevent update
collisions (not as the key, but as a substitute for a timestamp field).

What is the proper way to define storage for a guid in VB?

What is the proper way to define storage for a guid in SQL Server?

Thanks,

Dean Slindee

Nov 21 '05 #4
I use a GUID in an access database as follows:

'Create the Table with a column named KeyId of type GUID
sqlstring = "CREATE TABLE Items(KeyID GUID PRIMARY KEY)

'To Add a new Row to Table using sql direct into Database;
Dim rowid As String = get_NewItemID()
sqlstring = "INSERT INTO Items (KeyID) VALUES ('" & rowid & "')

'To Add a new Row to Table using a DataSet where DBDataSet is a dataset
you've created which has the table ITEMS in it.
Dim r As DataRow
r = DBDataSet.Tables("Items").NewRow
r.Item("KeyID") = New Guid(get_NewItemID())
DBDataSet.Tables("Items").Rows.Add(r)
DBCmd = New OleDb.OleDbCommand("SELECT * FROM Items", DBConn)
DBAdapt.SelectCommand = DBCmd
DBAdapt.Update(DBDataSet, "Items")

'Function used to create unique GUID using date and time and last ID
Private Function get_NewItemID() As String
Static lastid As Long
Static id1 As Integer
Dim id2, id3 As Short
Dim nw As DateTime = DateTime.Now
Dim thisid As Long = nw.Ticks
id1 = id1 + 1 : id2 = CType(nw.DayOfYear, Short) : id3 =
CType(nw.Year, Short)
If thisid = lastid Then thisid = thisid + 1
lastid = thisid
'You must create a function to covert an integer to a 8 byte array
Dim b As Byte() = ConvIntegertoByteArray(thisid, 8)
Return New Guid(id1, id2, id3, b).ToString
End Function
--

Hope this helps...There's probably a simpler way to do it but this works for
me.

Dennis in Houston
"Dean Slindee" wrote:
I would like to use a Guid as a record identifier for to prevent update
collisions (not as the key, but as a substitute for a timestamp field).

What is the proper way to define storage for a guid in VB?

What is the proper way to define storage for a guid in SQL Server?

Thanks,

Dean Slindee

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gijs Korremans | last post by:
> Does IPADDRESSSTRUCT appear anywhere in the makepy-generated module ? Specifically, there should be a RecordMap dict containing any defined Records and their GUID's. No it's not in the...
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 ?
1
by: John Smith | last post by:
Hi all, I've got this math problem... I feel a little bit silly but here it is, because it seems first year CS, but my memory fails me. Sample Code: Guid myGuid = new...
2
by: Ereck | last post by:
How do I use Option Strict with a GUID: Here is the code sample. Convert does not have a 128 integer type nor GUID type. So how do I make a GUID Type Safe? Public Function Load(ByVal iGUID As...
6
by: Bernd Koehler | last post by:
Hi: I am a EE prof currently teaching an IT course. One the assignments students recently completed was designing a small MS Access Database. I have two submissions that are remarkably...
9
by: Rene | last post by:
I am using the Guid.Empty value ("00000000-0000-0000-0000-000000000000") to represent a special meaning. The problem is that I don't know if there is a chance that a command like...
6
by: SevDer | last post by:
Is there a way to test guid string? I want to do it without try catch block to save on performance. Thanks in advance. -- SevDer
5
by: gbraux | last post by:
Hello, I am trying to implement IInternetZoneManager Com Interface into my c# project to be able to programaticaly edit the "Require server verification (HTTPS) for all sites in this zone"...
13
by: Lamefif | last post by:
// The GUID is represented as a structure defined in <winnt.h>. typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4;} GUID; GUID is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.