473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to assign primary key to more than one field

Hello Sir,
How to assign more than one primary key to table by this below following
code. i am able assign to a single field only. how to assign primary key to
more than one field. the primary key assigning code line is symboled kept
with in the *************** in the below code.

'Creating database

Dim cat As Catalog = New Catalog

cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")

cat = Nothing

MsgBox("Database succesfully created")

End If

'creating tables in the database

'

' This code adds a single-field Primary key

'

Dim Cn As ADODB.Connection

Dim Cat2 As ADOX.Catalog

Dim objTable1, objtable2 As ADOX.Table

Cn = New ADODB.Connection

Cat2 = New ADOX.Catalog

objTable1 = New ADOX.Table

objtable2 = New ADOX.Table

'Open the connection

Try

Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source= " & Application.StartupPath & "\databases" & "\" & fname1 &
";" & "Jet OLEDB:Engine Type=5")

'"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\sample\gaffar.mdb"

Catch ex As Exception

MsgBox(ex.Message)

End Try

'Open the Catalog

Cat2.ActiveConnection = Cn

'Create the table

objTable1.Name = "Test_Table"

objtable2.Name = "Test_Table2"

'Create and Append a new field to the "Test_Table" Columns Collection

objTable1.Columns.Append("company", DataTypeEnum.adVarWChar)

objTable1.Columns.Append("contact", DataTypeEnum.adVarWChar)
'Create and Append a new key. Note that we are merely passing

'the "PimaryKey_Field" column as the source of the primary key. This

'new Key will be Appended to the Keys Collection of "Test_Table"

'dsclient.Tables(0).PrimaryKey = New DataColumn

'{dsClient.Tables(0).Columns("FirstName"),

'dsClient.Tables(0).Columns("LastName")}

************************************************** **************************
*****************

objTable1.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyPrimary, "company")

************************************************** **************************
*****************

'Append the newly created table to the Tables Collection

Try

Cat2.Tables.Append(objTable1)

Catch ex As Exception

MsgBox(ex.Message)

End Try

Cat2.Tables.Append(objtable2)

' clean up objects

' objKey = Nothing

objTable1 = Nothing

objtable2 = Nothing

Cat2 = Nothing
Nov 21 '05 #1
2 1399
Gaffar,

In my opinion is that on this page

http://msdn.microsoft.com/library/de...eyfortable.asp

I hope this helps?

Cor
Nov 21 '05 #2
Gaffar,

In my opinion is that on this page

http://msdn.microsoft.com/library/de...eyfortable.asp

I hope this helps?

Cor
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mavis Tilden | last post by:
Hi all, So I've been reading the newsgroups, and reading a few books trying to learn SQL and SQL Server 2000. The books tell me I need a Primary Key, and that every table should have one. I know...
1
by: gaffar | last post by:
Hello Sir, How to assign more than one primary key to table by this below following code. i am able assign to a single field only. how to assign primary key to more than one field. the primary key...
2
by: Megan | last post by:
Hi everybody- I have 2 tables, Hearings and Rulings. Both have primary keys called, CaseID, that are autonumbers. I don't want both tables to have the same autonumber. For example, if Hearings...
0
by: gaffar | last post by:
Hello Sir, How to assign more than one primary key to table by this below following code. i am able assign to a single field only. how to assign primary key to more than one field. the primary key...
2
by: dBNovice | last post by:
Hi all! I have 3 separate forms: Tasks, Subtasks, and Elements. All 3 is related by TaskId and Subtasks and Elements are related by SubtaskID. In the DB after I add a task, I want to be able to...
8
by: Paul Hunter | last post by:
I am new to databases and thus to Access. I have a situation where I am trying to figure out how to key some tables I am working with. Consider that I have a database of my own records which are...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
1
by: mark_aok | last post by:
Hi all, I have a situation where I need to determine a specific table's primary key, and then output it. I have tried the Database Object, and the Record Object, but I've had no luck. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.