﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » CopyDataFrom</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 14 Sep 2026 18:51:34 GMT</lastBuildDate><ttl>20</ttl><item><title>CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26900.aspx</link><description>I wish to make a copy of some data by loading the original, changing the name of a queue that it belongs to and writing it back to the BO but preserving the original data. When I look at the individual rows, the data is changed, but nothing seems to be saved into the backend database. Have I misinterpreted the use of CopyDataFrom: Please see attached code snippet&lt;/P&gt;&lt;P&gt;Many thanks for any assistance.&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.localPrintQBO.FillWithQueueItems(&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;Global&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.CurrentUserId, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;Global&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.CurrentTableId, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;._currentPrintQ);&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;DataTable&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; loTable = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;DataTable&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;();&lt;/P&gt;&lt;P&gt;loTable = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.localPrintQBO.CurrentDataTable.Clone();&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;DataRow&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; qRow &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.localPrintQBO.CurrentDataTable.Rows)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;loTable.ImportRow(qRow);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;//Change the copy to the target print queue&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; (&lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;DataRow&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; qRow &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; loTable.Rows)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;qRow[&lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;&lt;FONT color=#800000 size=2&gt;"QName"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;] = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.cboTargetQ.Text.ToString();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.localPrintQBO.CopyDataFrom(loTable, &lt;/FONT&gt;&lt;FONT color=#008080 size=2&gt;&lt;FONT color=#008080 size=2&gt;BusinessCloneDataType&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;.AppendDataToTableFromCompleteTable);&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;[/codesnippet]</description><pubDate>Tue, 20 Apr 2010 09:29:19 GMT</pubDate><dc:creator>Ian Hammond</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26936.aspx</link><description>Many thanks, guys, that works a treat.&lt;/P&gt;&lt;P&gt;Regards</description><pubDate>Tue, 20 Apr 2010 09:29:19 GMT</pubDate><dc:creator>Ian Hammond</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26924.aspx</link><description>Yep, Charles' approach would definately be the cleanest for this application, IMO. We do similar things several places in our own apps. Something like this:&lt;/P&gt;&lt;P&gt;[codesnippet]//-- Create a new instance to copy into&lt;BR&gt;MyBo MyNewBo = new MyBo();&lt;BR&gt;foreach ( MyBO bo in MyBoInstance.GetEnumerable( ) )&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp; //-- Create a new row&lt;BR&gt;&amp;nbsp;&amp;nbsp; MyNewBo.NewRow( );&lt;BR&gt;&amp;nbsp;&amp;nbsp; //-- Set the necessary values (the ones that should not be default, and should be different than the source BO)&lt;BR&gt;&amp;nbsp;&amp;nbsp; MyNewBo.mb_CustomField = //-- Whatever value is appropriate;&lt;BR&gt;&amp;nbsp;&amp;nbsp; //-- Copy the values&lt;BR&gt;&amp;nbsp;&amp;nbsp; foreach ( DataColumn col in MyNewBo.CurrentDataTable.Columns )&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Skip certain columns&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if((col.ColumnName.Equals("mb_pk",StringComparison.OrdinalIgnoreCase)) ||&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (col.ColumnName.Equals("mb_CustomField", StringComparison.OrdinalIgnoreCase)) ||&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (col.ColumnName.Equals("mb_CreatedAt",StringComparison.OrdinalIgnoreCase)) ||&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (col.ColumnName.Equals("mb_CreatedBy",StringComparison.OrdinalIgnoreCase)) ||&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (col.ColumnName.Equals("mb_Version",StringComparison.OrdinalIgnoreCase)))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; continue;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Try to update the value&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyNewBo.CurrentRow[col.ColumnName] = bo.CurrentRow[col.ColumnName];&lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}[/codesnippet]&lt;/P&gt;&lt;P&gt;&lt;BR&gt;&amp;nbsp;</description><pubDate>Tue, 20 Apr 2010 08:28:47 GMT</pubDate><dc:creator>Dustin Taylor</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26922.aspx</link><description>If you are copying data, are you copying it into the same BO?  I mean, if you start with 10 records in the BO, do you want to end up with 20 records with just a different Qnumber for the added 10?  &lt;br&gt;
&lt;br&gt;
If so, I would create a new instance of the BO, iterate the BO you want to copy from using Getenumerable as Greg showed, and use newrow() in the second BO, generating a new PK and copy the field values to the new BO record, substituting the Q number you want.  &lt;br&gt;
&lt;br&gt;</description><pubDate>Tue, 20 Apr 2010 07:59:25 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26919.aspx</link><description>Thanks Guys for your input. I liked the different slant on the code and also I learned some other techniques when using Strataframe. Unfortunatelly the code gave the same results I was experiencing. I replaced the final Save with the changedPrintQBO and this did Save data in the database but overwrote the original data that I was trying to Copy. I think the issues are related to the primary key which is copied across from the source BO to the&amp;nbsp;destination BO.&lt;/P&gt;&lt;P&gt;Again, many thanks</description><pubDate>Tue, 20 Apr 2010 05:10:52 GMT</pubDate><dc:creator>Ian Hammond</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26916.aspx</link><description>Setting the QName via the BO should dirty it as well.</description><pubDate>Mon, 19 Apr 2010 19:12:48 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26907.aspx</link><description>Hi Ian,&lt;/P&gt;&lt;P&gt;I believe the problem is that the BO.CopyDataFrom() method does no copy the BO.EditingState for each record, so if you need to save the data you need to loop each record and set the EditingState property to Add or Edit.&lt;/P&gt;&lt;P&gt;I am not at my office so I cannot give you exact code, but I am almost sure that happened to me once.</description><pubDate>Mon, 19 Apr 2010 13:52:06 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: CopyDataFrom</title><link>http://forum.strataframe.net/FindPost26903.aspx</link><description>I'm not quite sure I follow what you are trying to do. Does the original data not have a PK?  Or are you not loading the PK in the fill method? I'm asking because that could cause some issues when reloading the data and then attempting to save it. &lt;br&gt;
&lt;br&gt;
Some other things to think about. You could use the CopyDataFrom both directions, you need to save the changes to the BO and I'd grab the queue name before I enter the loop:&lt;br&gt;
&lt;br&gt;
[codesnippet]//-- Load original print queue items&lt;br&gt;
this.localPrintQBO.FillWithQueueItems(Global.CurrentUserId, Global.CurrentTableId, this._currentPrintQ);&lt;br&gt;
&lt;br&gt;
//-- Use another BO rather than a datatable. I'm going to guess&lt;br&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;that the BOs name is PrintQBO.&lt;br&gt;
PrintQBO changedPrintQBO = new PrintQBO;&lt;br&gt;
changedPrintQBO.CopyDataFrom(localPrintQBO, BusinessCloneDataType.ClearAndFillFromCompleteTable); &lt;br&gt;
&lt;br&gt;
//-- Get the new queues name from UI.&lt;br&gt;
string newQueue = this.cboTargetQ.Text.ToString();&lt;br&gt;
&lt;br&gt;
//Change the copy to the target print queue&lt;br&gt;
foreach (PrintQBO qRow in changedPrintQBO.GetEnumerable())&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;qRow.QName = newQueue;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
//-- This appends the data, but if the PK was copied, I'm not sure what &lt;br&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;this will do. It would either add another set of rows to the&lt;br&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;datatable, with duplicate PKs (bad) or update the original &lt;br&gt;
//&amp;nbsp;&amp;nbsp;&amp;nbsp;data with the changed data (bad). Unless I'm missing something...&lt;br&gt;
this.localPrintQBO.CopyDataFrom(changedPrintQBO, BusinessCloneDataType.AppendDataToTableFromCompleteTable);&lt;br&gt;
&lt;br&gt;
//-- Save the data.&lt;br&gt;
this.localPrintQBO.Save();[/codesnippet]&lt;br&gt;
&lt;br&gt;
Let me know if that helped. :D</description><pubDate>Mon, 19 Apr 2010 11:33:57 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>