Create table with code like:
DataTable dtMaster = new DataTable("Master");In this example I will add Columns without specifying type:
dtMaster.Columns.Add("Id");Create new row:
DataRow drMaster = dtMaster.NewRow(); drMaster["Id"] = 1;Add row to DataTable:
dtMaster.Rows.Add(drMaster);Now details table:
DataTable dtDetail = new DataTable("Details"); dtDetail.Columns.Add("Id"); dtDetail.Columns.Add("FkDetailMasterId"); DataRow drDetail = dtDetail.NewRow(); drDetail["Id"] = 1; drDetail["FkDetailMasterId"] = 1; dtDetail.Rows.Add(drDetail);Create DataSet and add relation:
DataSet ds = new DataSet(); ds.Tables.Add(dtMaster); ds.Tables.Add(dtDetail); DataRelation relMasterDetail = new DataRelation("MyRelation" , ds.Tables["Master"].Columns["Id"] , ds.Tables["Details"].Columns["FkDetailMasterId"] ); ds.Relations.Add(relMasterDetail);Example download from here.