tags:

views:

65

answers:

4

i'm trying create guid autonumber field programaticaly but i cant. help me please. i'm using c#.

A: 

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}})
Remou
this is a only create guid field and insert new record.i need create guid and autoincrement field.
Baris
A: 

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())"
HansUp
Is this the same as setting ReplicationID for an Autonumber field in the table designer within Access? If not, what's the difference?
David-W-Fenton
Yes, that's how it's displayed in the Access UI. He didn't say why he wants to do it from C#.
HansUp
I read the question as being about populating an existing field, as opposed to adding the field to a table.
David-W-Fenton
A: 

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
David