473,654 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1576

"Dean Slindee" <sl*****@charte r.net> wrote in message
news:fp******** ***********@fe0 4.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() = RowThatContains GuidId.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 "uniqueidentifi er" 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
"uniqueidentifi er" field in your tables is generally a good idea.
"Dean Slindee" <sl*****@charte r.net> wrote in message
news:fp******** ***********@fe0 4.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 uniqueidentifie r 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.Table s("Items").NewR ow
r.Item("KeyID") = New Guid(get_NewIte mID())
DBDataSet.Table s("Items").Rows .Add(r)
DBCmd = New OleDb.OleDbComm and("SELECT * FROM Items", DBConn)
DBAdapt.SelectC ommand = 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.DayOfY ear, 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() = ConvIntegertoBy teArray(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
1517
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 genereted module, but it is in the COM Browser so I'm sure the struct is in the com object Maybe I can find out somewhere what the GUID's is and put it in the RecodMap manually? Roger
24
10875
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
498
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 Guid("fccf281d-47bd-45c7-8f2b-a48d462d171b"); Int64 myGuidInt = BitConverter.ToInt64(myGuid.ToByteArray(),0); this.textBox1.Text = myGuid.ToString(); this.textBox2.Text = myGuidInt.ToString(); Byte me = myGuid.ToByteArray(); this.textBox3.Text = "";
2
1983
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 Guid) As Structures.Record Implements Interfaces.Record.Load Dim cn As New SqlConnection(SQL.Connection.Info.SQLConnectionString) Dim cmd As New SqlCommand Dim da As New SqlDataAdapter
6
2278
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 similiar..<sigh> the structure (number of tables, field names, table names) is virtually identical. Some of the data in each table is different.
9
34831
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 "Guid.NewGuid()"would generate a Guid.Empty value could this be possible or is the "00000000-0000-0000-0000-000000000000" Guid reserved or something like that? Thank you.
6
7191
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
2777
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" checkbox in IE zones. This Interface provide a SetZoneAttributes() Method that could help me to acheive this goal. But I don't find this class in my registry (Vista / IE7, even on a Win03 / IE6).
13
5890
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 128-bit number ? but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7306
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.