Generating a GUID with VB.NET

Introduction

This code generates Globally Unique Identifier (GUID), which can be used to uniqually identify elements in a database.

GUIDs identify objects such as interfaces and class objects. A GUID consists of one group of 8 hexadecimal digits, followed by three groups of 4 hexadecimal digits each, which are followed by one group of 12 hexadecimal digits.

Possessing a unique identifier makes it easy to store and retrieve information. This is especially useful when working with a database because a GUID makes an excellent primary key.

SQL Server integrates well with GUID usage. The SQL Server data type uniqueidentifier stores a GUID value. You can either generate this value within SQL Server—using the NEWID() function—or you can generate the GUID outside of SQL Server and insert it manually.

The base System class in the .NET Framework includes the GUID value type. In addition, this value type includes methods to work with GUID values. In particular, the NewGUID method allows you to easily generate a new GUID.

Language and Platform

VB.NET 2005

Compiler

This code segment is for VB.NET 2005

Version

1.0.0.0

Code

    Private Sub GenerateGUID()
        Dim strGUID As String        
        strGUID = System.Guid.NewGuid.ToString()        
        MessageBox.Show(strGUID )
    End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值