|
-
Jun 8th, 2003, 10:36 AM
#1
Thread Starter
Sleep mode
Relations + ADO.NET ?[Resolved]
I'm coding that in C# . I got error says : "This constraint cannot be enabled as not all values have corresponding parent values "
Since this forum for VB.NET only , I posted here to get some examples if you have seen one on the net .
edit : I thought someone can figure out what I'm missing here , so I posted the code , sorry .
Thanks
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";
}
Last edited by Pirate; Jun 8th, 2003 at 05:15 PM.
-
Jun 8th, 2003, 05:14 PM
#2
Thread Starter
Sleep mode
Re: Relations + ADO.NET ?
I fixed it . .
If you are interested , click here for the answer .http://www.vbforums.com/showthread.p...98#post1456198
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|