yx074464
July 15th, 1999, 06:35 AM
How can I set up a primary key in ADO connection to create table ? Thanks
|
Click to See Complete Forum and Search --> : Primary Key yx074464 July 15th, 1999, 06:35 AM How can I set up a primary key in ADO connection to create table ? Thanks freek July 15th, 1999, 07:09 AM here you have an example of how to make a new table, it also includes a primary key Sub NewTable() Dim dbs as Database Dim tdf as TableDef, fld1 as Field, fld2 as Field Dim idx as Index, fldIndex as Field ' Return reference to current database. set dbs = CurrentDb ' Create new table with two fields. set tdf = dbs.CreateTableDef("Contacts") set fld1 = tdf.CreateField("ContactID", dbLong) fld1.Attributes = fld1.Attributes + dbAutoIncrField set fld2 = tdf.CreateField("ContactName", dbText, 50) ' Append fields. tdf.Fields.Append fld1 tdf.Fields.Append fld2 ' Create primary key index. set idx = tdf.CreateIndex("PrimaryKey") set fldIndex = idx.CreateField("ContactID", dbLong) ' Append index fields. idx.Fields.Append fldIndex ' set Primary property. idx.Primary = true ' Append index. tdf.Indexes.Append idx ' Append TableDef object. dbs.TableDefs.Append tdf dbs.TableDefs.Refresh set dbs = nothing End Sub Lothar Haensler July 15th, 1999, 07:09 AM conn.execute "create table x( col1 varchar(10) primary key)" at least this works for SQLServer. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |