Saturday, December 17, 2011

Data set with Data Relation in

Here i will shown how to give the primary key and foreign key to tables .Data set having collection of data table and data relations.while generating relations in the data set at least we have to store two tables .while creating the tables we have to create tables with Primary key constraint and with foreign key constraint.The p.k constraint column table is master table and F.K constraint column table is child table.The P.K constraint column automatically controls F.K constraint column values

Data Relation:This class is used to generate relation in the database .This class takes constructor arguments
1.Relation name
2.Primary Key Constraint Column
3.Foreign Key Constraint Column
Using System.Data.Oledb;

OledbConnection cn=New OledbConnection("Provider=msdaora.1;user id=test;pasword=test");
OledbDataAdapter ad1;
OledbDataAdapter ad2;
Dataset ds=new Dataset();
DataRelation dr;
//under button click event
ad1=New OledbDataAdapter("select*from Employee",cn);
ad1=New OledbDataAdapter("select*from Department",cn);
DataColumn PK=ds.Tables["Employee"].columns["empid"];
DataColumn FK=ds.Tables["Department"].columns["empidid"];
dr=New DataRealtion("re1",PK,FK);

No comments: