Creating relations in MS Access with C#
Hi,
I want to check/ create a relation between 2 tables in an Access database. Sofar I didn't find any commands that seem to go over a relationship in Access.
Does anybody know if there is such a command?
Jorn
Kirtan PatelPosted Nov 23, 2009, 10:44 AM
if my answer helps you then please check "Do you like this answer check box " :)
OledbConnection con = new OledbConnection("Connection String");
con.Open();
//Adding Primary Key
OledbCommand comm = new OledbCommand("alter table Table1 add constraint pk_id primary key(id)",con);
comm.ExecuteNonQuery();
//Adding Foriegn Key
comm = new OledbCommand("alter table Table2 add constraint fk_id foreign key(id) references Table1(id)",con);
comm.ExecuteNonQuery();
con.Close();