I'm getting this error that says : "This constraint cannot be enabled as not all values have corresponding parent values "
I'm getting data from two relational tables . Hmm , have a look at the code .
How can I solve this problem ?![]()
Code:public void ShowInGrid() { DataSet ds; //two commands for MainCat_Tab & SubCat_Tab tables System.Data.OleDb.OleDbCommand cmd; System.Data.OleDb.OleDbCommand cmd2; //two adapters for filling ds obj System.Data.OleDb.OleDbDataAdapter adp; System.Data.OleDb.OleDbDataAdapter adp2; //this handles the relationship between //the two columns System.Data.DataRelation datarelation; System.Data.DataColumn dc1; System.Data.DataColumn dc2; ds =new DataSet(); ds.CaseSensitive=true; //First command for first table cmd=new OleDbCommand (); cmd.Connection=DBSpace.FunctionClass.MyConnection; cmd.CommandText="SELECT * FROM MainCat_Tab"; //Second command for Second table cmd2=new OleDbCommand (); cmd2.Connection=DBSpace.FunctionClass.MyConnection; cmd2.CommandText="SELECT * FROM SubCat_Tab"; //first table adp=new OleDbDataAdapter (); adp.SelectCommand =cmd; adp.TableMappings.Add("Table","MainCat_Tab"); adp.Fill(ds); //Second table adp2=new OleDbDataAdapter (); adp2.SelectCommand=cmd2; adp2.TableMappings.Add ("Table","SubCat_Tab"); adp2.Fill(ds); dc1=ds.Tables["MainCat_Tab"].Columns["MainCat_ID"]; dc2=ds.Tables["SubCat_Tab"].Columns["SubCat_ID"]; datarelation=new System.Data.DataRelation("MainCat_TabToSubCat_Tab",dc1,dc2); ds.Relations.Add (datarelation); Here is the error dataGrid1.DataSource=ds;//.DefaultViewManager; dataGrid1.DataMember="MainCat_Tab"; }





Reply With Quote