<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Federation Method</title><link>https://www.aras.com/community/f/development/3860/federation-method</link><description>I&amp;#39;m trying to use a method for a federation item type that appends data into Aras, but it&amp;#39;s only inserting one record, I&amp;#39;m assuming the (do while) is incorrect, any help would be appreciated

 

System.Data.OleDb.OleDbCommand com = new System.Data.OleDb</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Federation Method</title><link>https://www.aras.com/community/thread/1892?ContentTypeID=1</link><pubDate>Mon, 27 Aug 2018 12:46:17 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:073fe3d8-a952-48b5-a149-b5e370cb49a3</guid><dc:creator>didonato</dc:creator><description>Question 1.

How do I retrieve the number of rows in myDataReader, is there a (int count = myDataReader.RowCount) ??

Question 2                                                                                                                                                                                                                                           If place a place holder for my count for testing ex. (int count = 2) it always doubles my data, If I put (int count =3) it triples my data. I&amp;#39;m assuming there&amp;#39;s something wrong in my code

&amp;nbsp;

// Get the serial number
Item qry0 = this.newItem(&amp;quot;MIN_Delivered_Component&amp;quot;);
qry0.setAttribute(&amp;quot;select&amp;quot;,&amp;quot;item_number&amp;quot;);
qry0.setID(this.getProperty(&amp;quot;source_id&amp;quot;));
Item res=qry0.apply(&amp;quot;get&amp;quot;);
if (res.isError()) return res;

// get the Serial Number (key) that we will use in the external database to search on.
string masterserial;
masterserial = res.getProperty(&amp;quot;item_number&amp;quot;);

// Connect to external database
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(@&amp;quot;Provider=SQLOLEDB;Data Source=000.00.000.0; Initial Catalog=ABC; User ID=admin;Password=xxxxx;&amp;quot;);
string sqltext = &amp;quot;select dc, trans_group, part_number where serial_number = &amp;#39;&amp;quot; + masterserial + &amp;quot;&amp;#39;;&amp;quot;;
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(sqltext);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();

//create a MIN_Delivered_Transaction item
Item res5 = this.newItem(&amp;quot;MIN_Delivered_Transaction&amp;quot;);
string newid = getNewID();
res5.setID(newid);
res5 = res5.apply();

int count = 2;
while (myDataReader.Read()) {
for(int i = 0 ; i &amp;lt; count ; i++) {
Item temp = this.newItem(&amp;quot;MIN_Delivered_Transaction&amp;quot;);
temp.setProperty(&amp;quot;f_dc&amp;quot;, myDataReader.GetString(0));
temp.setProperty(&amp;quot;f_trans_group&amp;quot;, myDataReader.GetString(1));
temp.setProperty(&amp;quot;f_part_number&amp;quot;,myDataReader.GetString(2));
res5.appendItem(temp); // Add a new item for each iteration of the loop
}
}
myConnection.Close();
return res5;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Federation Method</title><link>https://www.aras.com/community/thread/1891?ContentTypeID=1</link><pubDate>Fri, 10 Aug 2018 08:25:32 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:03a76e0e-a3ee-4bb4-b10f-a0e9b8b1bd67</guid><dc:creator>didonato</dc:creator><description>This is partially working, it’s bring back the result twice and the first record is always blank. Ex:

Blank Line-------
AA 123
BB 456
AA 123
BB 456

See my code below, thanks for your help!!

string sqltext = &amp;quot;select dc, trans_group, part_number, part_name, serial_number, trans_number, trans_type, trans_name, created_by, state, call_ticket, created_on from P81M.dbo.min_transactions_all where serial_number = &amp;#39;&amp;quot; + masterserial + &amp;quot;&amp;#39;;&amp;quot;;
System.Data.OleDb.OleDbCommand com = new System.Data.OleDb.OleDbCommand(sqltext);
com.Connection = myConnection;
myConnection.Open();
System.Data.OleDb.OleDbDataReader myDataReader = com.ExecuteReader();

//create a MIN_Delivered_Transaction item
Item res5 = this.newItem(&amp;quot;MIN_Delivered_Transaction&amp;quot;);
string newid = getNewID();
res5.setID(newid);
res5 = res5.apply();

// int count = myDataReader.FieldCount;
int count = 1;
while (myDataReader.Read()) {
for(int i = 0 ; i &amp;lt; count ; i++) {
Item temp = this.newItem(&amp;quot;MIN_Delivered_Transaction&amp;quot;);
temp.setProperty(&amp;quot;f_dc&amp;quot;, myDataReader.GetString(0));
temp.setProperty(&amp;quot;f_trans_group&amp;quot;, myDataReader.GetString(1));
temp.setProperty(&amp;quot;f_part_number&amp;quot;,myDataReader.GetString(2));
temp.setProperty(&amp;quot;f_part_name&amp;quot;,myDataReader.GetString(3));
temp.setProperty(&amp;quot;f_serial_number&amp;quot;,myDataReader.GetString(4));
temp.setProperty(&amp;quot;f_trans_number&amp;quot;,myDataReader.GetString(5));
temp.setProperty(&amp;quot;f_trans_type&amp;quot;,myDataReader.GetString(6));
temp.setProperty(&amp;quot;f_trans_name&amp;quot;,myDataReader.GetString(7));
temp.setProperty(&amp;quot;f_created_by&amp;quot;,myDataReader.GetString(8));
temp.setProperty(&amp;quot;f_state&amp;quot;,myDataReader.GetString(9));
temp.setProperty(&amp;quot;f_call_ticket&amp;quot;,myDataReader.GetString(10));
res5.appendItem(temp); // Add a new item for each iteration of the loop
}
}
myConnection.Close();
return res5;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Federation Method</title><link>https://www.aras.com/community/thread/1890?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 14:54:27 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:f72e2481-c6ab-4197-84a2-f6db09b8f1b7</guid><dc:creator>Christopher Gillis</dc:creator><description>Hello,

The loop seems to be correct, but the code is just overwriting the data in the &lt;strong&gt;res5&lt;/strong&gt; variable each time instead of creating a new item. You&amp;#39;ll want to change it to be something like the example below.

&lt;pre&gt;&lt;code&gt;while(myDataReader.Read()) {
for (int i = 0; i &amp;lt; count; i++) {
Item temp = this.newItem(&amp;quot;MIN_Delivered_Transaction&amp;quot;);
temp.setProperty(&amp;quot;f_dc&amp;quot;, myDataReader.GetString(0));
temp.setProperty(&amp;quot;f_trans_group&amp;quot;, myDataReader.GetString(0));
...
res5.appendItem(temp); // Add a new item for each iteration of the loop
}
}
...
return res5;&lt;/code&gt;&lt;/pre&gt;


This will return &lt;strong&gt;res5&lt;/strong&gt; as a collection of items like you are expecting.

Chris

&lt;hr /&gt;

Christopher Gillis

Aras Labs Software Engineer&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>