如何使用DAO为Access数据库的表编程创建主键字段? RRS feed

  • 问题

  • 我想使用DAO 3.6操作Access数据库,给其中的某个表创建一个字段,类型为“自动编号”的“同步复制ID”,要求它能够自动创建GUID值,然后把它设定为主键。这个怎么做?
    2015年5月24日 12:12


  • 你好,



    Shared Function CommandString(sType As DatabaseType) As ArrayList
            Dim result As New ArrayList
            Select Case sType
                Case DatabaseType.sample1
                    result.Add("CREATE TABLE sample1 ([id] COUNTER IDENTITY(1,1), [SessionId] VARCHAR (40), [SessionDate] DATETIME, [SessionName] LONGTEXT, CONSTRAINT PKSessions PRIMARY KEY (SessionId))")
                Case DatabaseType.sample2
                    result.Add("CREATE TABLE Roles ([id] COUNTER IDENTITY(1,1), [Rolename] LONGTEXT, [ApplicationName] LONGTEXT, CONSTRAINT PKRoles PRIMARY KEY (Rolename, ApplicationName))")
                    result.Add("CREATE TABLE UsersInRoles ([id] COUNTER IDENTITY(1,1), [Username] LONGTEXT, [Rolename] LONGTEXT, [ApplicationName] LONGTEXT, CONSTRAINT PKUsersInRoles PRIMARY KEY (Username, Rolename, ApplicationName))")
            End Select
            Return result
        End Function

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年5月28日 1:37