|
-
Jul 1st, 2002, 12:33 PM
#1
Thread Starter
Junior Member
primary key.....
i know how to create table and rows and columns of .mdb file in visual basic but how to set a primary key on any field.How is it possible.
-
Jul 2nd, 2002, 01:05 AM
#2
Fanatic Member
Hi
First at all I don't use the primary key anymore. It is annoying, hehe.
Better is in my opinion to create in Access the Indexes that you need and then just activate them in VB. If you use ADO then is it:
recordset.index ="NameCity" (if you created an index with name and city)
If you make then recordset.MoveFirst then you are on the first record of this Indexsort.
With recordset.Seek is it possible to seek then a record. Specially if you have many records is the index good.
My experience is that with less then 10.000 records is no index needed. Sort and Find is fast enough.
Franky
-
Jul 2nd, 2002, 01:06 AM
#3
Hyperactive Member
Hello Sujaanpals,
Try this code:
Private Sub Command1_Click()
Dim Ws As Workspace
Dim Db As Database
If Dir("c:\q.mdb") <> "" Then Kill ("c:\q.mdb")
Set Ws = DBEngine.Workspaces(0)
Set Db = Ws.CreateDatabase("c:\q.mdb", dbLangGeneral)
SqlSel = "Create Table Customer ( Customer Text, Project TEXT CONSTRAINT MyFieldConstraint PRIMARY KEY"
SqlSel = SqlSel + ", Plant" + " text"
SqlSel = SqlSel + ");"
Db.Execute SqlSel
Db.Close
End Sub
Nice regards,
Michelle.
-
Jul 2nd, 2002, 01:19 AM
#4
Fanatic Member
Hi
Be aware that the method from Michelle is very dangerous for existing data, because it recreate always a new EMPTY Table.
Franky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|