<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7291562660860062970</id><updated>2011-04-30T04:52:17.374-07:00</updated><title type='text'>Programming Aid</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-6778701740120217193</id><published>2008-12-06T10:02:00.000-08:00</published><updated>2008-12-06T10:10:23.946-08:00</updated><title type='text'>Programming Aid Coad</title><content type='html'>&lt;ol style="color: rgb(102, 102, 102);" class="dp-j" start="1"&gt;&lt;li class="alt"&gt;&lt;span&gt;&lt;span class="keyword"&gt;try&lt;/span&gt;&lt;span&gt; {  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// Call a function that takes NO parameters&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs = connection.prepareCall(&lt;span class="string"&gt;"{call procedure_name}"&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs.execute(); &lt;span class="comment"&gt;//execute the stored procedure&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// Call a function that takes a String IN parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;span class="comment"&gt;// An IN parameters is when you input a value&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// for the stored procedure&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs = connection.prepareCall(&lt;span class="string"&gt;"{call procedure_name_in(?)}"&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs.setString(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="string"&gt;"ABC"&lt;/span&gt;&lt;span&gt;); &lt;/span&gt;&lt;span class="comment"&gt;// Set the value for the IN parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs.execute();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// Call a function that returns a String OUT parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;span class="comment"&gt;// An OUT parameter is when the stored procedure&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// has an output value&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs = connection.prepareCall(&lt;span class="string"&gt;"{call procedure_name_out(?)}"&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs.registerOutParameter(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;, Types.VARCHAR);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// Register the types of the return value and OUT parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs.execute();  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  String outParam = cs.getString(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;); &lt;/span&gt;&lt;span class="comment"&gt;// OUT parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;span class="comment"&gt;// Call a function with one IN/OUT parameter&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;span class="comment"&gt;// An IN/OUT parameter has been an input and an output&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs = connection.prepareCall(&lt;span class="string"&gt;"{call procedure_name_inout(?)}"&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs.registerOutParameter(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;, Types.VARCHAR);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  cs.setString(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="string"&gt;"ABC"&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;  cs.execute();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  String outParam = cs.getString(&lt;span class="number"&gt;1&lt;/span&gt;&lt;span&gt;);  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;} &lt;span class="keyword"&gt;catch&lt;/span&gt;&lt;span&gt; (SQLException e) {  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;} &lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-6778701740120217193?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/6778701740120217193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=6778701740120217193' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/6778701740120217193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/6778701740120217193'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/programming-aid-coad.html' title='Programming Aid Coad'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-5262933265395107985</id><published>2008-12-06T10:00:00.001-08:00</published><updated>2008-12-06T10:01:55.332-08:00</updated><title type='text'>CallableStatement for Java</title><content type='html'>&lt;p style="color: rgb(102, 0, 0);"&gt;I recently learned how to call a stored procedure using Java.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;CallableStatement is used when a Java application needs to call a stored procedure. The stored procedure contains the SQL query to be executed on the database and is stored on the database.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;To use CallableStatement, the Java code will need to first import the CallableStatement class.&lt;/p&gt;&lt;p style="color: rgb(102, 0, 0);"&gt;connection is the connection to the database, and prepareCall is the method used to call the stored procedure. The syntax used in the prepareCall parameters is shown above, but replace procedure_name with the actual stored procedure name.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;Next, use cs.execute(); to execute. So to put it together, you will need to add it to try/catch block as shown below:&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-5262933265395107985?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/5262933265395107985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=5262933265395107985' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/5262933265395107985'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/5262933265395107985'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/callablestatement-for-java_06.html' title='CallableStatement for Java'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-9143160080876438550</id><published>2008-12-06T10:00:00.000-08:00</published><updated>2008-12-06T10:01:53.569-08:00</updated><title type='text'>CallableStatement for Java</title><content type='html'>&lt;p style="color: rgb(102, 0, 0);"&gt;I recently learned how to call a stored procedure using Java.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;CallableStatement is used when a Java application needs to call a stored procedure. The stored procedure contains the SQL query to be executed on the database and is stored on the database.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;To use CallableStatement, the Java code will need to first import the CallableStatement class.&lt;/p&gt;&lt;p style="color: rgb(102, 0, 0);"&gt;connection is the connection to the database, and prepareCall is the method used to call the stored procedure. The syntax used in the prepareCall parameters is shown above, but replace procedure_name with the actual stored procedure name.&lt;/p&gt; &lt;p style="color: rgb(102, 0, 0);"&gt;Next, use cs.execute(); to execute. So to put it together, you will need to add it to try/catch block as shown below:&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-9143160080876438550?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/9143160080876438550/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=9143160080876438550' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/9143160080876438550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/9143160080876438550'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/callablestatement-for-java.html' title='CallableStatement for Java'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-5516447057628384775</id><published>2008-12-06T09:59:00.000-08:00</published><updated>2008-12-06T10:00:41.090-08:00</updated><title type='text'>Sample Code on Website</title><content type='html'>&lt;p&gt;&lt;span style="color: rgb(51, 51, 153);"&gt;You may have noticed the fancing code snippets that accompany many of the tutorials on this website! I would love to say I developed this myself, but the truth is that this is a free resource free for anybody to download and use. It is called SyntaxHighlighter and can be found at&lt;/span&gt; &lt;a title="Syntax Highlighter" href="http://code.google.com/p/syntaxhighlighter/" target="_blank"&gt;http://code.google.com/p/syntaxhighlighter/&lt;/a&gt;.&lt;/p&gt; &lt;p style="color: rgb(153, 102, 51);"&gt;&lt;strong&gt;What is Included?&lt;/strong&gt;&lt;/p&gt; &lt;p style="color: rgb(51, 102, 102);"&gt;So what does the Syntax Highlighter come with? Below is a list my favorite features of this software:&lt;/p&gt; &lt;ol style="color: rgb(51, 102, 102);"&gt;&lt;li&gt;It’s completely free!&lt;/li&gt;&lt;li&gt;Associate keywords for supported languages are highlighted.&lt;/li&gt;&lt;li&gt;Each line of code is numbered and colored for easier reading!&lt;/li&gt;&lt;li&gt;Allows one click to code only view.&lt;/li&gt;&lt;li&gt;Allows one click copy to clipboard of code.&lt;/li&gt;&lt;li&gt;Allows one click copy to printer.&lt;/li&gt;&lt;/ol&gt; &lt;p style="color: rgb(51, 102, 102);"&gt;&lt;strong&gt;What Comes With the Download&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="color: rgb(51, 102, 102);"&gt;The file can be downloaded from their official website at&lt;/span&gt; &lt;a title="Syntax Highlighter" href="http://code.google.com/p/syntaxhighlighter/" target="_blank"&gt;http://code.google.com/p/syntaxhighlighter/&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;as a rar compressed file. Inside the compressed file, you will find various folders and files. The core files that are required include:&lt;/span&gt;&lt;/p&gt; &lt;ol style="color: rgb(0, 153, 0);"&gt;&lt;li&gt;clipboard.swf&lt;/li&gt;&lt;li&gt;shCore.js&lt;/li&gt;&lt;li&gt;SyntaxHighlighter.css&lt;/li&gt;&lt;/ol&gt; &lt;p style="color: rgb(0, 153, 0);"&gt;Still, there are many more JavaScript files that have been included in the download. Not all of these files are required. Instead, you choose additional optional JavaScript files for the programming or scripting languages you want the Syntax Highlighter to associate.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-5516447057628384775?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/5516447057628384775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=5516447057628384775' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/5516447057628384775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/5516447057628384775'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/sample-code-on-website.html' title='Sample Code on Website'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-4468411408486922635</id><published>2008-12-06T09:58:00.001-08:00</published><updated>2008-12-06T09:58:56.702-08:00</updated><title type='text'>C# Dictionary Collection</title><content type='html'>&lt;p style="color: rgb(102, 102, 102);"&gt;A Dictionary object in C# has become one of my recent favorites. Below are a few important aspects:&lt;/p&gt; &lt;ol style="color: rgb(102, 102, 102);"&gt;&lt;li&gt;Requires including &lt;code&gt;System.Collections.Generic;&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Each entry in a Dictionary is a KeyValuePair (consisting of two objects: key and value)&lt;/li&gt;&lt;li&gt;The key must be unique&lt;/li&gt;&lt;li&gt;The value does not need to be unique&lt;/li&gt;&lt;li&gt;Both the key and value can be any object (string, int, custom class, etc…)&lt;/li&gt;&lt;li&gt;Retrieving a value via a key take close to O(1) time&lt;/li&gt;&lt;li&gt;The order of a KeyValuePair enumeration is not defined&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-4468411408486922635?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/4468411408486922635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=4468411408486922635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/4468411408486922635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/4468411408486922635'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/c-dictionary-collection.html' title='C# Dictionary Collection'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7291562660860062970.post-1479111928139117240</id><published>2008-12-06T09:56:00.000-08:00</published><updated>2008-12-06T09:57:57.432-08:00</updated><title type='text'>C# programmer deals</title><content type='html'>&lt;p style="color: rgb(153, 102, 51);"&gt;At some point, every C# programmer deals with populating, selecting, and even deleting from a DataTable. A moderately advanced operation is transferring an entire single row from an original DataTable and inserting it into a new DataTable. My original thoughtprocess is the following:&lt;/p&gt; &lt;div style="color: rgb(153, 102, 51);" class="dp-highlighter"&gt;&lt;div class="bar"&gt;&lt;div class="tools"&gt;view plaincopy to clipboardprint?&lt;/div&gt;&lt;/div&gt;&lt;ol style="color: rgb(51, 51, 51);" class="dp-c" start="1"&gt;&lt;li class="alt"&gt;&lt;span&gt;&lt;span&gt;DataTable originalTable = &lt;/span&gt;&lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; DataTable();  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;int&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;DataRow dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 1;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Victor"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Chen"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 5;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"M"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 2;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"John"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Doe"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 35;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"M"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 3;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Jane"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Doe"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 32;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"F"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;DataTable newTable = originalTable.Clone();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;newTable.Rows.Add(originalTable.Rows[1]);  &lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;pre style="display: none;" name="code" class="C#"&gt;DataTable originalTable = new DataTable(); originalTable.Columns.Add("id", typeof(int)); originalTable.Columns.Add("firstName", typeof(string)); originalTable.Columns.Add("lastName", typeof(string)); originalTable.Columns.Add("age", typeof(string)); originalTable.Columns.Add("gender", typeof(string));  DataRow dr = originalTable.NewRow(); dr["id"] = 1; dr["firstName"] = "Victor"; dr["lastName"] = "Chen"; dr["age"] = 5; dr["gender"] = "M"; originalTable.Rows.Add(dr);  dr = originalTable.NewRow(); dr["id"] = 2; dr["firstName"] = "John"; dr["lastName"] = "Doe"; dr["age"] = 35; dr["gender"] = "M"; originalTable.Rows.Add(dr);  dr = originalTable.NewRow(); dr["id"] = 3; dr["firstName"] = "Jane"; dr["lastName"] = "Doe"; dr["age"] = 32; dr["gender"] = "F"; originalTable.Rows.Add(dr);  DataTable newTable = originalTable.Clone(); newTable.Rows.Add(originalTable.Rows[1]);&lt;/pre&gt; &lt;p style="color: rgb(153, 102, 51);"&gt;Though the above example is long, lines 1 - 30 handle creating and populating the original DataTable (If you need explanation of how this works, check out Add Rows to a DataTable in C# tutorial). Line 32 creates a new DataTable by taking the structure of the original DataTable. In Line 33, we attempt to select Row 1 from the original DataTable and add it as a new row in the new DataTable. However, the above example above does not work. It will throw the runtime error below.&lt;/p&gt; &lt;blockquote style="color: rgb(153, 102, 51);"&gt;&lt;p&gt;This row already belongs to another table.&lt;/p&gt;&lt;/blockquote&gt; &lt;p style="color: rgb(153, 102, 51);"&gt;The correct solution takes more lines of coding (and therefore more logic), but ultimately gets the job done. It involves using a DataRow’s ItemArray method to transfer a row’s data column by column through an object array, and inserting them column by column back into a new DataRow. See the example below:&lt;/p&gt; &lt;div style="color: rgb(153, 102, 51);" class="dp-highlighter"&gt;&lt;div class="bar"&gt;&lt;div class="tools"&gt;view plaincopy to clipboardprint?&lt;/div&gt;&lt;/div&gt;&lt;ol style="color: rgb(51, 102, 102);" class="dp-c" start="1"&gt;&lt;li class="alt"&gt;&lt;span&gt;&lt;span&gt;DataTable originalTable = &lt;/span&gt;&lt;span class="keyword"&gt;new&lt;/span&gt;&lt;span&gt; DataTable();  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;int&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Columns.Add(&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span class="keyword"&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class="keyword"&gt;string&lt;/span&gt;&lt;span&gt;));  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;DataRow dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 1;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Victor"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Chen"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 5;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"M"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 2;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"John"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Doe"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 35;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"M"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr = originalTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"id"&lt;/span&gt;&lt;span&gt;] = 3;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"firstName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Jane"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"lastName"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"Doe"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"age"&lt;/span&gt;&lt;span&gt;] = 32;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;dr[&lt;span class="string"&gt;"gender"&lt;/span&gt;&lt;span&gt;] = &lt;/span&gt;&lt;span class="string"&gt;"F"&lt;/span&gt;&lt;span&gt;;  &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;originalTable.Rows.Add(dr);  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;DataTable newTable = originalTable.Clone();  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;DataRow newRow = newTable.NewRow();  &lt;/span&gt;&lt;/li&gt;&lt;li class=""&gt;&lt;span&gt;newRow.ItemArray = originalTable.Rows[1].ItemArray;  &lt;/span&gt;&lt;/li&gt;&lt;li class="alt"&gt;&lt;span&gt;newTable.Rows.Add(newRow);  &lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;pre style="display: none;" name="code" class="C#"&gt;DataTable originalTable = new DataTable(); originalTable.Columns.Add("id", typeof(int)); originalTable.Columns.Add("firstName", typeof(string)); originalTable.Columns.Add("lastName", typeof(string)); originalTable.Columns.Add("age", typeof(string)); originalTable.Columns.Add("gender", typeof(string));  DataRow dr = originalTable.NewRow(); dr["id"] = 1; dr["firstName"] = "Victor"; dr["lastName"] = "Chen"; dr["age"] = 5; dr["gender"] = "M"; originalTable.Rows.Add(dr);  dr = originalTable.NewRow(); dr["id"] = 2; dr["firstName"] = "John"; dr["lastName"] = "Doe"; dr["age"] = 35; dr["gender"] = "M"; originalTable.Rows.Add(dr);  dr = originalTable.NewRow(); dr["id"] = 3; dr["firstName"] = "Jane"; dr["lastName"] = "Doe"; dr["age"] = 32; dr["gender"] = "F"; originalTable.Rows.Add(dr);  DataTable newTable = originalTable.Clone(); DataRow newRow = newTable.NewRow(); newRow.ItemArray = originalTable.Rows[1].ItemArray; newTable.Rows.Add(newRow);&lt;/pre&gt; &lt;p style="color: rgb(153, 102, 51);"&gt;Keeping consistent with our original example, lines 1-30 handle creating a DataTable. On line 32, create a DataTable. On Line 32, create a new DataRow. On Line 33, I select Row 1 from the Original DataTable, take it’s ItemArray, and transfer it to the newly created DataRow from Line 32. Finally, on line 34, I transfer newRow into the newTable.&lt;/p&gt; &lt;p style="color: rgb(153, 102, 51);"&gt;If you have more than one row you would like to copy, merely repeat this process through a loop. Happy Coding!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7291562660860062970-1479111928139117240?l=programmingaid.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://programmingaid.blogspot.com/feeds/1479111928139117240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7291562660860062970&amp;postID=1479111928139117240' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/1479111928139117240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7291562660860062970/posts/default/1479111928139117240'/><link rel='alternate' type='text/html' href='http://programmingaid.blogspot.com/2008/12/c-programmer-deals.html' title='C# programmer deals'/><author><name>sign</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_oewa-GVAGzI/SliykqCEFCI/AAAAAAAAAD0/24KipgZJxUM/S220/Picture+243.jpg'/></author><thr:total>0</thr:total></entry></feed>
