table creation with code and relations

albertsmus
03-24-2005, 02:32 AM
i create an access table with the following code:

Dim oledbcommand As OleDb.OleDbCommand

oledbcommand = New OleDb.OleDbCommand
oledbcommand.Connection = cond
oledbcommand.CommandType = CommandType.Text
oledbcommand.CommandText = "create table customers(PtPelUnique autoincrement primary key,eponimo text(50),epagelma text(50),dieuthinsi text(50),poli text(25),tk text(5),tel text(15),email text(50),afm text(10),fax text(15),doi text(15),TelHome text(15),Mobile text(15),nomos text(15),Ptmemo memo) "

Try
oledbcommand.ExecuteNonQuery()

Catch ex As System.Data.OleDb.OleDbException

End Try

with similar code i create a table with name ptAgores (the fields are ptUnique autoincrement and PtPelunique )


now i try to create a relation between the two tables with the folowing lines of code:


oledbcommand = New OleDb.OleDbCommand
oledbcommand.Connection = cond
oledbcommand.CommandType = CommandType.Text
oledbcommand.CommandText = " ALTER TABLE ptAgores " & _
" ADD FOREIGN KEY PtPelunique TAG " & _
" PtPelunique REFERENCES customers"

Try
oledbcommand.ExecuteNonQuery()

Catch ex As System.Data.OleDb.OleDbException

End Try

i got an error here, in the commandtext. what am i doing wrong?
Thanks for any help.

MKoslof
03-28-2005, 09:00 AM
What is the error that you receive?

albertsmus
03-29-2005, 08:51 AM
the error i receive is that there is an error in references!
Thanks for help!

albertsmus
03-29-2005, 08:59 AM
i beleive that ther is something in the sql syntax!

MKoslof
03-29-2005, 09:05 AM
Conduct your SQL syntax like so:


ALTER TABLE T1 ADD CONSTRAINT ClientID
FOREIGN KEY([ClientCode]) REFERENCES T2 ([ClientCode])

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum