473,385 Members | 1,465 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,385 software developers and data experts.

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("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
Jul 21 '05 #1
1 2234
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
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...
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...
3
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...
2
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...
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: 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...
20
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...
2
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...
2
by: vanishree | last post by:
Hi Plz Guide Me How To Assign Composite Primary Key
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.