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
2010-08-26 09:16:01
this is a only create guid field and insert new record.i need create guid and autoincrement field.
Baris
2010-08-26 10:05:45
+1
A:
This might be helpful:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q180841
Also, using DAO:
Jerome
2010-08-26 11:39:13
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
2010-08-26 11:51:56
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
2010-08-27 20:07:16
Yes, that's how it's displayed in the Access UI. He didn't say why he wants to do it from C#.
HansUp
2010-08-27 20:46:45
I read the question as being about populating an existing field, as opposed to adding the field to a table.
David-W-Fenton
2010-08-28 19:52:05
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
2010-08-26 12:07:47