开发者

How to create GUID Autonumber programmatically in ms access

How do I create guid autonumber field programmatic开发者_StackOverflow社区ally using C#?


In order to make your GUID field auto-increment, use GenGUID() as it's default value.

This works in Access using ADO. Perhaps a similar statement will work in C#:

CurrentProject.Connection.Execute "CREATE TABLE hede (Id Guid DEFAULT GenGUID())"


If its C# then

string myguid = Guid.NewGuid.ToString;

If its Access then

Private Declare Function CreateGuid Lib "OLE32.DLL" (pGuid As GUID) As Long
Private Declare Function StringFromGUID2 Lib "OLE32.DLL" (pGuid As GUID, ByVal PointerToString As Long, ByVal MaxLength As Long) As Long

Private Type GUID
    Guid1           As Long
    Guid2           As Integer
    Guid3           As Integer
    Guid4(0 To 7)   As Byte
End Type

Public Function CreateGUIDKey() As String
    Const GUID_OK As Long = 0    
    Const GUID_LENGTH As Long = 38

    Dim udtGUID As GUID
    Dim FormattedGUID As String
    Dim Result As Long

    Result = CreateGuid(udtGUID)

    If Result = GUID_OK Then
        FormattedGUID = String$(GUID_LENGTH, 0)
        StringFromGUID2 udtGUID, StrPtr(FormattedGUID), GUID_LENGTH + 1
    Else
        FormattedGUID = ""
    End If

    CreateGUIDKey = FormattedGUID

End Function


This might be helpful:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q180841

Also, using DAO:

What is the MS Access SQL syntax to create a field of type Hyperlink?


Do you know how to run sql against a Jet or ACE connection?

CREATE TABLE Literal (LinkID GUID)

INSERT INTO Literal (LinkID) VALUES ({guid {11223344-1122-1122-1122-AABBCCDDEEFF}})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜