Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

Parent expression columns not updating after DataSet merging...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Baulch - 26 Oct 2004 08:49 GMT
When merging a DataTable of fresh data into my DataSet, the expression
columns in my other table that links to that table (using the
PARENT(RELATION).FIELD syntax) are not updated. The only way I have managed
to get it working is using an ugly workaround whereby I re-set the
DataColumn's expression and re-set the DataGrid's source straight after the
merge.

The following code should illustrate my problem. Create a new Form, drop a
DataGrid and two Buttons on it and paste the following code in the
appropriate places.

private DataSet _Set;
private DataTable _Parent;
private DataTable _Child;

private void button1_Click(object sender,EventArgs e)
{
   _Parent = new DataTable("PARENT");
   _Parent.PrimaryKey = new DataColumn[]
       {_Parent.Columns.Add("ID")};
   _Parent.Columns.Add("TEXT1");
   _Parent.Rows.Add(new object[] {"1","10"});
   _Parent.Rows.Add(new object[] {"2","20"});
   _Parent.Rows.Add(new object[] {"3","30"});

   _Child = new DataTable("CHILD");
   _Child.PrimaryKey = new DataColumn[]
       {_Child.Columns.Add("ID")};
   _Child.Columns.Add("TEXT2");
   _Child.Rows.Add(new object[] {"1","one"});
   _Child.Rows.Add(new object[] {"2","two"});
   _Child.Rows.Add(new object[] {"3","three"});

   _Set = new DataSet();
   _Set.Tables.Add(_Parent);
   _Set.Tables.Add(_Child);
   _Set.Relations.Add("PARENTCHILD",
       _Parent.PrimaryKey[0],_Child.PrimaryKey[0]);
   _Child.Columns.Add("TEXT1",typeof(string),
       "PARENT(PARENTCHILD).TEXT1");

   dataGrid.DataSource = _Child;
}

private void button2_Click(object sender, System.EventArgs e)
{
   DataTable newParent = _Parent.Clone();
   newParent.Rows.Add(new object[] {"1","ten"});
   newParent.Rows.Add(new object[] {"2","twenty"});
   newParent.Rows.Add(new object[] {"3","thirty"});
   _Set.Merge(newParent);

   //the following 4 lines make up my ugly workaround.
   DataColumn col = _Child.Columns["TEXT1"];
   col.Expression = col.Expression;
   dataGrid.DataSource = null;
   dataGrid.DataSource = _Child;
}

Nato
Sijin Joseph - 26 Oct 2004 13:57 GMT
You can try and call Refresh() on the CurrencyManager for the datagrid.

dataGrid.BindingContext[_Child].Refresh();

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> When merging a DataTable of fresh data into my DataSet, the expression
> columns in my other table that links to that table (using the
[quoted text clipped - 56 lines]
>
> Nato

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.