473,654 Members | 3,082 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to assign more than one primary key

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("Pro vider=Microsoft .Jet.OLEDB.4.0; " & _

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

cat = Nothing

MsgBox("Databas e succesfully created")

End If

'creating tables in the database

'

' This code adds a single-field Primary key

'

Dim Cn As ADODB.Connectio n

Dim Cat2 As ADOX.Catalog

Dim objTable1, objtable2 As ADOX.Table

Cn = New ADODB.Connectio n

Cat2 = New ADOX.Catalog

objTable1 = New ADOX.Table

objtable2 = New ADOX.Table

'Open the connection

Try

Cn.Open("Provid er=Microsoft.Je t.OLEDB.4.0;" & _

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

'"Provider=Micr osoft.Jet.OLEDB .4.0;Data Source=d:\sampl e\gaffar.mdb"

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

'Open the Catalog

Cat2.ActiveConn ection = Cn

'Create the table

objTable1.Name = "Test_Table "

objtable2.Name = "Test_Table 2"

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

objTable1.Colum ns.Append("comp any", DataTypeEnum.ad VarWChar)

objTable1.Colum ns.Append("cont act", DataTypeEnum.ad VarWChar)
'Create and Append a new key. Note that we are merely passing

'the "PimaryKey_Fiel d" column as the source of the primary key. This

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

'dsclient.Table s(0).PrimaryKey = New DataColumn

'{dsClient.Tabl es(0).Columns(" FirstName"),

'dsClient.Table s(0).Columns("L astName")}

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

objTable1.Keys. Append("Primary Key", KeyTypeEnum.adK eyPrimary, "company")

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

'Append the newly created table to the Tables Collection

Try

Cat2.Tables.App end(objTable1)

Catch ex As Exception

MsgBox(ex.Messa ge)

End Try

Cat2.Tables.App end(objtable2)

' clean up objects

' objKey = Nothing

objTable1 = Nothing

objtable2 = Nothing

Cat2 = Nothing
Jul 21 '05 #1
1 2249
Gaffar,

In my opinion is that on this page

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

I hope this helps?

Cor
Jul 21 '05 #2

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

Similar topics

5
1945
by: Vishal Sinha | last post by:
Here is my issue. I have a list of merchants (generated daily) and I need to assign them eually to a set of analysts. Both the merchant list and analyst list can change daily. I want to assign each merchant with an analyst daily and need help to write out a stored procedure for this (do not want to use VB). Here is relevant code for the tables: CREATE TABLE MerchList ( MerchListID int IDENTITY (1, 1) NOT NULL , FileDate datetime NOT NULL...
2
2284
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 has 55, then I want Rulings to have a number greater than 55. Two or more Hearings may be entered before a Ruling is entered. For example, Hearings with CaseIDs= 55, 56, and 57 may be entered before a Ruling or vice versa. There is no definite...
3
2104
by: peddie | last post by:
Hi, I have a table that contains two key fields. I would like to assign the auto number for the secondary key field by starting from 1. For example primary Key id second Key Id ------------------ ----------------------------------------- 1 1 1 2 1 3
2
1412
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 assigning code line is symboled kept with in the *************** in the below code. 'Creating database Dim cat As Catalog = New Catalog
1
334
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 assigning code line is symboled kept with in the *************** in the below code. 'Creating database Dim cat As Catalog = New Catalog
2
2984
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 add one or more subtasks and then one or more elements. I need the subtasks and elements to be have the same taskid as the task; also I want the element to have the same subtaskId as the subtask. I have been able to design the system to include...
20
14237
by: keri | last post by:
Hi, I am creating a table where I want to use the date as the primary key - and to automatically create a record for each working date (eg Mon to Fri) until 30 June 2007. Is this possible? I do not want my user to have to create a record for each date. Thanks,
2
3149
by: Birky | last post by:
Assign the output of a select to a variable? I am unable to find a way to assign the results of an SQL statement to a variable. I know how to assign the SQL statement to a variable but again no luck assigning the results. I have the need to assign the primary key of a table, which is an auto number data type) therefore a numeric value. My select is very basic for I am just looking for the primary key where two options are met. "SELECT...
2
2002
by: vanishree | last post by:
Hi Plz Guide Me How To Assign Composite Primary Key
0
8814
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.