<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.dotnetzone.gr:443/cs/utility/FeedStylesheets/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>WinForms</title><link>https://www.dotnetzone.gr:443/cs/forums/12/ShowForum.aspx</link><description>Θέματα για rich client / windows εφαρμογές, σε οποιαδήποτε γλώσσα (VB.NET, C#, managed C++, κ.α.)</description><dc:language>el</dc:language><generator>CommunityServer 2.1 SP3 (Build: 20423.1)</generator><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16830.aspx</link><pubDate>Mon, 18 Sep 2006 16:23:18 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16830</guid><dc:creator>gmlogic</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16830.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16830</wfw:commentRss><description>Σας ευχαριστώ όλους για τη βοήθεια :)&lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16690.aspx</link><pubDate>Wed, 13 Sep 2006 21:04:33 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16690</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16690.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16690</wfw:commentRss><description>&lt;P&gt;Επίσης, αν χρησιμοποιείς την getchanges, ενημερώνεις, και μετά κάνεις merge στο αρχικό dataset, πρέπει να έχεις υπόψη σου κάποια πράγματα που αναφέρονται εδώ: &lt;A href="http://msdn2.microsoft.com/en-us/library/ks9f57t0.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ks9f57t0.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Δες το σημείο που μιλάει για "Merging New Identity Values".&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16689.aspx</link><pubDate>Wed, 13 Sep 2006 21:00:53 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16689</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16689.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16689</wfw:commentRss><description>&lt;P&gt;1) δημιουργώ commandbuilder&lt;BR&gt;&lt;BR&gt;2) παίρνω insert command (σε προσωρινή μεταβλητή, όχι στον adapter)&lt;BR&gt;&lt;BR&gt;3) τροποποιώ insert command : προσθέτω στο τέλος του command text ένα SELECT MyIdentityColumn, Col1, Col2 .... FROM MyTable WHERE MyIdentityColumn=SCOPE_IDENTITY()&lt;BR&gt;&lt;BR&gt;4) αλλάζω το UpdatedRowSource του insert command σε Both&lt;/P&gt;
&lt;P&gt;5) &lt;STRONG&gt;εκτελώ το commandBuilder.RefreshSchema&lt;/STRONG&gt;&lt;BR&gt;&lt;BR&gt;6) θέτω το insert command στον adapter&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16639.aspx</link><pubDate>Wed, 13 Sep 2006 00:58:27 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16639</guid><dc:creator>gmlogic</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16639.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16639</wfw:commentRss><description>Ok Μάνο ευχαριστώ&lt;br /&gt;
&lt;br /&gt;
Μήπως θα μπορούσε ο Δημήτρης να μας στείλει ένα παραδειγματάκι.&lt;br /&gt;
&lt;br /&gt;
Γιατί λέει οτι του δουλεύει με το RefreshSchema σε ποιά σημεία το βάζη?&lt;br /&gt;
&lt;br /&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16633.aspx</link><pubDate>Wed, 13 Sep 2006 00:12:40 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16633</guid><dc:creator>KelMan</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16633.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16633</wfw:commentRss><description>&lt;P&gt;H DbCommandBuilder είναι abstract base class που σημαίνει ότι δεν μπορείς να την χρησιμοποιήσεις απ'ευθείας, δηλαδή δεν μπορείς να πεις &lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; command_builder &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; DbCommandBuilder(...)&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;και γι αυτόν το λόγο δεν έχει την clone μέθοδο.&lt;/P&gt;
&lt;P&gt;Σχετικά με το RefreshSchema, στο MSDN λέει: &lt;/P&gt;
&lt;P&gt;&lt;BLOCKQUOTE&gt;&lt;table width="85%"&gt;&lt;tr&gt;&lt;td class="quoteTable"&gt;&lt;table width="100%"&gt;&lt;tr&gt;&lt;td valign="top" class="txt4"&gt;&lt;BR&gt;The &lt;B&gt;DbCommandBuilder&lt;/B&gt; also uses the &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbcommand.connection.aspx"&gt;Connection&lt;/A&gt;&lt;/SPAN&gt;, &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbcommand.commandtimeout.aspx"&gt;CommandTimeout&lt;/A&gt;&lt;/SPAN&gt;, and &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbcommand.transaction.aspx"&gt;Transaction&lt;/A&gt;&lt;/SPAN&gt; properties referenced by the &lt;B&gt;SelectCommand&lt;/B&gt;. The user should call &lt;B&gt;RefreshSchema&lt;/B&gt; if any of these properties are modified, or if the &lt;B&gt;SelectCommand&lt;/B&gt; itself is replaced. Otherwise the &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbdataadapter.insertcommand.aspx"&gt;InsertCommand&lt;/A&gt;&lt;/SPAN&gt;, &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbdataadapter.updatecommand.aspx"&gt;UpdateCommand&lt;/A&gt;&lt;/SPAN&gt;, and &lt;SPAN class=linkTerms&gt;&lt;A href="http://msdn2.microsoft.com/en-us/library/system.data.common.dbdataadapter.deletecommand.aspx"&gt;DeleteCommand&lt;/A&gt;&lt;/SPAN&gt; properties retain their previous values.&lt;BR&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/BLOCKQUOTE&gt;&lt;/P&gt;
&lt;P&gt;Πραγματικά, δεν μπορώ να φανταστώ το πως μπορεί να βοηθήσει το RefreshSchema από την στιγμή που αλλάζεις το CommandText property του InsertCommand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16606.aspx</link><pubDate>Tue, 12 Sep 2006 18:52:41 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16606</guid><dc:creator>gmlogic</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16606.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16606</wfw:commentRss><description>Ok Μάνο το κατάλαβα και μου δούλεψε.&lt;BR&gt;&lt;BR&gt;Μόνο υπάρχει ένα μικρό πρόβλημα&lt;BR&gt;&lt;BR&gt;Όταν δίνω DataAdapterCategories.InsertCommand = CommandBuilderCategories.GetInsertCommand.Clone&lt;BR&gt;&lt;BR&gt;γιά να δουλέψει επειδή όπως επισήμανες και συ αν δεν δώσω clone δεν κρατάει το &lt;BR&gt;&lt;BR&gt;SELECT @@IDENTITY AS ColumnI&lt;BR&gt;&lt;BR&gt;Επειδή χρησιμοποιώ το παραδειγμά σου &lt;BR&gt;&lt;BR&gt;&lt;FONT color=#ff0000&gt;Dim command_builder As DbCommandBuilder = dataFactory.CreateCommandBuilder()&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;το clone δεν υπάρχει&lt;BR&gt;&lt;BR&gt;Μήπως το RefreshSchema που λέει ο Δημήτρης πέζει?&lt;BR&gt;&lt;BR&gt;Πάντως με το &lt;BR&gt;&lt;BR&gt;Dim CommandBuilderCategories As New SqlCommandBuilder(DataAdapterCategories)&lt;BR&gt;&lt;BR&gt;Πέζει μιά χαρά</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16584.aspx</link><pubDate>Tue, 12 Sep 2006 03:21:56 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16584</guid><dc:creator>KelMan</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16584.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16584</wfw:commentRss><description>Όταν γίνεται το Update από τον DataAdapter η νέα τιμή του ID μπαίνει στην θέση της παλιάς μέσα στο DataRow. Κοίταξε τον κώδικα step-by-step, την δεύτερη φορά που τρέχει η PrintRows μπορείς να διαβάσεις την τιμή και να την περάσεις σε μεταβλητή.</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16559.aspx</link><pubDate>Mon, 11 Sep 2006 21:40:39 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16559</guid><dc:creator>gmlogic</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16559.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16559</wfw:commentRss><description>Μου έμεινε ένα κενό για την δεύτερη λύση.&lt;br /&gt;
&lt;br /&gt;
Πώς πέρνω το ColumnID σε μιά μεταβλητή?&lt;br /&gt;
&lt;br /&gt;
Καί πάλι σας ευχαριστώ</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16532.aspx</link><pubDate>Mon, 11 Sep 2006 16:32:13 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16532</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16532.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16532</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;table width="85%"&gt;&lt;tr&gt;&lt;td class="txt4"&gt;&lt;img src="/cs/Themes/default/images/icon-quote.gif"&gt;&amp;nbsp;&lt;strong&gt;KelMan wrote:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="quoteTable"&gt;&lt;table width="100%"&gt;&lt;tr&gt;&lt;td valign="top" class="txt4"&gt;
&lt;P&gt;Δεν ξέρω τα inner workings του DataAdapter, ενδεχομένως να ξανακαλεί κάποια στιγμή την GetInsertCommand. Εν κατακλείδει, το πρόβλημα τελικά λύνεται αν πούμε &lt;/P&gt;
&lt;P&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/BLOCKQUOTE&gt;&lt;/P&gt;
&lt;P&gt;Και εγώ δεν τα ξέρω, αλλά επειδή όντως κάτι συμβαίνει εκεί, το refreshschema το λύνει. Εγώ το βάζω αφού έχω πάρει το insert command από τον commandbuilder και το έχω τροποποιήσει&amp;nbsp;και πριν το θέσω στον adapter.&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16528.aspx</link><pubDate>Mon, 11 Sep 2006 08:42:35 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16528</guid><dc:creator>KelMan</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16528.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16528</wfw:commentRss><description>&lt;P&gt;OK, ανακάλυψα τι φταίει στο δεύτερο σενάριο και τώρα μπορώ να πάω για ύπνο...&lt;/P&gt;
&lt;P&gt;Λοιπον, οι δύο βασικές εντολές είναι:&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; CommandBuilderCategories.GetInsertCommand&lt;br /&gt;        DataAdapterCategories.InsertCommand.CommandText &amp;amp;= &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"; SELECT @@IDENTITY AS ColumnID"&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Από τον Profiler είδα ότι όταν ο DataAdapter στέλνει την InsertCommand, o SQL Server λαμβάνει προς εκτέλεση το παρακάτω:&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;exec&lt;/span&gt; &lt;span style="color: Brown;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;sp_executesql&lt;/span&gt; N&lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;'INSERT INTO [DataBuilderDemo] ([Column1]) VALUES (@p1)'&lt;/span&gt;,N&lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;'@p1 nvarchar(5)'&lt;/span&gt;,@p1=N&lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;'New Row'&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;που σημαίνει ότι άσχετα αν εμείς προσθέτουμε το "; SELECT @@IDENTITY AS ColumnID" στο τέλος του CommandText property, αυτό αγνοείται! Το κόλπο είναι να πάρουμε όλο το Command object&amp;nbsp;μέσω του CommandBuilder (γιατί μας ενδιαφέρει το CommandText αλλά και το Parameters collection) αλλά να μην διατηρήσουμε το reference στo&amp;nbsp; CommandBuilder ώστε μετά να μπορούμε να το αλλάξουμε. Δεν ξέρω τα inner workings του DataAdapter, ενδεχομένως να ξανακαλεί κάποια στιγμή την GetInsertCommand. Εν κατακλείδει, το πρόβλημα τελικά λύνεται αν πούμε &lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt; &lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; CommandBuilderCategories.GetInsertCommand.Clone&lt;br /&gt;        ...&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16527.aspx</link><pubDate>Mon, 11 Sep 2006 04:20:50 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16527</guid><dc:creator>KelMan</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16527.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16527</wfw:commentRss><description>To δοκίμασες; Που ακριβώς να πάει το RefreshSchema; Γιατί αν θυμάμαι καλά, το RefreshSchema απλά καθαρίζει τα Commands του CommandBuilder.</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16526.aspx</link><pubDate>Mon, 11 Sep 2006 04:06:42 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16526</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16526.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16526</wfw:commentRss><description>Το βρήκα! Η 2η λύση είναι εφικτή!&lt;br /&gt;
&lt;br /&gt;
Πρέπει να μπει κάπου εκεί και το CommandBuilderCategories.RefreshSchema()</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16525.aspx</link><pubDate>Mon, 11 Sep 2006 03:35:04 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16525</guid><dc:creator>KelMan</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16525.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16525</wfw:commentRss><description>&lt;P&gt;Λοιπόν, το κοίταξα το πρόβλημα κι έγραψα λίγο κώδικα για να δοκιμάσω στην πράξη αυτά που θεωρητικά είπαμε. Ανακεφαλαιώνοντας, έχουμε και λέμε:&lt;/P&gt;
&lt;P&gt;Υπάρχουν τρεις τρόποι για να κάνεις αυτό που θέλεις. Ας ξεκινήσουμε από τον πρώτο που είναι να χρησιμοποιήσεις το RowUpdated event του DataAdapter και την στιγμή που γράφεται κάθε εγγραφή να στέλνεις ένα Query που να ρωτάς το νέο ID. &lt;/P&gt;
&lt;P&gt;Σε όλα τα παραδείγματα, υποτίθεται ότι δουλεύουμε σε έναν πίνακα στη Northwind που τον έχω φτιάξει με αυτήν την εντολή &lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;CREATE&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;TABLE&lt;/span&gt; DataBuilderDemo(ColumnID &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;identity&lt;/span&gt; &lt;span style="color: Silver;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;NOT&lt;/span&gt; &lt;span style="color: Silver;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;NULL&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;PRIMARY&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;KEY&lt;/span&gt;, Column1 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;nvarchar&lt;/span&gt;(16) &lt;span style="color: Silver;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;NOT&lt;/span&gt; &lt;span style="color: Silver;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;NULL&lt;/span&gt;)&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;O κώδικας στην φόρμα έχει ως εξής:&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; ConnectionNorthwind &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlConnection(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"Data Source=.;Initial Catalog=Northwind;Integrated Security=True"&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; DataAdapterCategories &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlDataAdapter(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"SELECT ColumnID, Column1 FROM DataBuilderDemo"&lt;/span&gt;, ConnectionNorthwind)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; CommandBuilderCategories &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlCommandBuilder(DataAdapterCategories)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; DataTableCategories &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; DataTable&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; CommandRefresh &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlCommand(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"SELECT @@IDENTITY"&lt;/span&gt;, ConnectionNorthwind)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; CreateInsertCommandButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; CreateInsertCommandButton.Click&lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; CommandBuilderCategories.GetInsertCommand&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;AddHandler&lt;/span&gt; DataAdapterCategories.RowUpdated, &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;AddressOf&lt;/span&gt; RowUpdatedHandler&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; FillTableButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; FillTableButton.Click&lt;br /&gt;        DataAdapterCategories.Fill(DataTableCategories)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; AddNewRowButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; AddNewRowButton.Click&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; RowNew &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; DataRow&lt;br /&gt;        RowNew &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; DataTableCategories.NewRow&lt;br /&gt;        RowNew.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Item&lt;/span&gt;(0) &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; 0&lt;br /&gt;        RowNew.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Item&lt;/span&gt;(1) &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"New Row"&lt;/span&gt;&lt;br /&gt;        DataTableCategories.Rows.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Add&lt;/span&gt;(RowNew)&lt;br /&gt;&lt;br /&gt;        PrintRows(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"Rows before update:"&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; UpdateButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; UpdateButton.Click&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Try&lt;/span&gt;&lt;br /&gt;            DataAdapterCategories.Update(DataTableCategories)&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Catch&lt;/span&gt; ex &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; Exception&lt;br /&gt;            Console.WriteLine(ex.Message)&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Try&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        PrintRows(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"Rows after update:"&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; PrintRows(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; message &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;String&lt;/span&gt;)&lt;br /&gt;        Console.WriteLine(message)&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;For&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Each&lt;/span&gt; row &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; DataRow &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;In&lt;/span&gt; DataTableCategories.Rows&lt;br /&gt;            Console.WriteLine(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;String&lt;/span&gt;.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Format&lt;/span&gt;(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"    {0}, {1}"&lt;/span&gt;, row.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Item&lt;/span&gt;(0), row.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Item&lt;/span&gt;(1)))&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Next&lt;/span&gt; row&lt;br /&gt;&lt;br /&gt;        Console.WriteLine()&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; RowUpdatedHandler(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; SqlRowUpdatedEventArgs)&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;If&lt;/span&gt; e.Status &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; UpdateStatus.[Continue] &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;AndAlso&lt;/span&gt; (e.StatementType &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; StatementType.Insert) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Then&lt;/span&gt;&lt;br /&gt;            e.Row(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"ColumnID"&lt;/span&gt;) &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;CInt&lt;/span&gt;(CommandRefresh.ExecuteScalar)&lt;br /&gt;            e.Row.AcceptChanges()&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;If&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Προσοχή χρειάζεται στα εξής σημεία: Δεν μπορούμε να χρησιμοποιήσουμε SCOPE_IDENTITY() αντί για @@IDENTITY γιατί στη RowUpdatedHandler, κάθε φορά που τρέχουμε το CommandRefresh, δημιουργείται νέο connection και το SCOPE_IDENTITY() επιστρέφει null. Επίσης, αυτή η τεχνική δουλεύει και σε Access.&lt;/P&gt;
&lt;P&gt;Η δεύτερη τεχνική είναι να αλλάξεις το InsertCommand που σου δίνει ο CommandBuilder έτσι ώστε να έχεις ένα Batched Query. Στη νέα έκδοση των παραπάνω, καταργείται η ρουτίνα RowUpdatedHandler, και το περιεχόμενο της CreateInsertCommandButton_Click αλλάζει σε:&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; CreateInsertCommandButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; CreateInsertCommandButton.Click&lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; CommandBuilderCategories.GetInsertCommand&lt;br /&gt;        DataAdapterCategories.InsertCommand.CommandText &amp;amp;= &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"; SELECT @@IDENTITY AS ColumnID"&lt;/span&gt;&lt;br /&gt;        DataAdapterCategories.InsertCommand.UpdatedRowSource &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; UpdateRowSource.FirstReturnedRecord&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Όμως φρούδες οι ελπίδες... Το παραπάνω δεν δουλεύει αν και θα έπρεπε! Λέω "αν και θα έπρεπε" γιατί αν αντί γι αυτό, γράψουμε &lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; CreateInsertCommandButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; CreateInsertCommandButton.Click&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; InsertCommand &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; SqlCommand&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; strSQL &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;String&lt;/span&gt;&lt;br /&gt;        strSQL &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"INSERT INTO DataBuilderDemo (Column1) VALUES (@Column1); SELECT SCOPE_IDENTITY() AS ColumnID"&lt;/span&gt;&lt;br /&gt;        InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlCommand(strSQL, ConnectionNorthwind)&lt;br /&gt;        InsertCommand.Parameters.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Add&lt;/span&gt;(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"@Column1"&lt;/span&gt;, SqlDbType.NVarChar, 16, &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"Column1"&lt;/span&gt;)&lt;br /&gt;        InsertCommand.UpdatedRowSource &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; UpdateRowSource.FirstReturnedRecord&lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; InsertCommand&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;δηλαδή κατασκευάσουμε χειροκίνητα την InsertCommand, τότε παίζει! Απλά δεν του κάνει η InsertCommand που γυρίζει ο CommandBuilder, ακόμα κι αν προσθέσει κανείς στο τέλος το "; SELECT SCOPE_IDENTITY() AS ColumnID". Βασικά, έκανα πολλές δοκιμές αλλά δεν βρήκα καμιά ειδοποιό διαφορά ανάμεσα στα δύο Commands ώστε να καταλάβω τι δεν πάει καλά με το command που παράγει το CommandBuilder. Όποιος έχει όρεξη ας το ψάξει περισσότερο να μας πει.&lt;/P&gt;
&lt;P&gt;Υπάρχει και μία τρίτη τεχνική που είναι να χρησιμοποιήσεις stored procedure η οποία θα επιστρέφει ως output το νέο ID.&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;CREATE&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;PROCEDURE&lt;/span&gt; spInsertDataBuilderDemo &lt;br /&gt; (@ColumnID &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;int&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;OUTPUT&lt;/span&gt;, &lt;br /&gt;  @Column1 &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;nvarchar&lt;/span&gt;(16))&lt;br /&gt;&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;AS&lt;/span&gt; &lt;br /&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;INSERT&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;INTO&lt;/span&gt; tblAutoIncrementTest(Column1) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;VALUES&lt;/span&gt; (@Column1)&lt;br /&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;SELECT&lt;/span&gt; @ColumnID = &lt;span style="color: Fuchsia;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;SCOPE_IDENTITY&lt;/span&gt;()&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Και αντίστοιχα, η CreateInsertCommandButton_Click γίνεται κάπως έτσι:&lt;/P&gt;
&lt;P&gt;&lt;span style="color: Black;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt; CreateInsertCommandButton_Click(&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; sender &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Object&lt;/span&gt;, &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;ByVal&lt;/span&gt; e &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; System.EventArgs) &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Handles&lt;/span&gt; CreateInsertCommandButton.Click&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; InsertCommand &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; SqlCommand&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; strSQL &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;String&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Dim&lt;/span&gt; param &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;As&lt;/span&gt; SqlParameter&lt;br /&gt;        strSQL &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"spAutoIncrementTestInsert"&lt;/span&gt;&lt;br /&gt;        InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;New&lt;/span&gt; SqlCommand(strSQL, ConnectionNorthwind)&lt;br /&gt;        param &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; InsertCommand.Parameters.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Add&lt;/span&gt;(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"@ColumnID"&lt;/span&gt;, SqlDbType.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Int&lt;/span&gt;, 0, &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"ColumnID"&lt;/span&gt;)&lt;br /&gt;        param.Direction &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; ParameterDirection.Output&lt;br /&gt;        InsertCommand.Parameters.&lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Add&lt;/span&gt;(&lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"@Column1"&lt;/span&gt;, SqlDbType.NVarChar, 16, &lt;span style="color: #666666;background-color: #e4e4e4;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;"Column1"&lt;/span&gt;)&lt;br /&gt;        InsertCommand.CommandType &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; CommandType.StoredProcedure&lt;br /&gt;        InsertCommand.UpdatedRowSource &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; UpdateRowSource.OutputParameters&lt;br /&gt;        DataAdapterCategories.InsertCommand &lt;span style="color: Red;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;=&lt;/span&gt; InsertCommand&lt;br /&gt;    &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;End&lt;/span&gt; &lt;span style="color: Blue;background-color: Transparent;font-family: Courier New;font-size: 11px;font-weight: normal;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Από τις τρεις λύσεις, εφόσον θέλεις απαραιτήτως να χρησιμοποιήσεις CommandBuilder ουσιαστικά σου κάνει μόνο η πρώτη. Θα σου πρότεινα να επανεξετάσεις το κατά πόσο είναι εφικτό να μην χρησιμοποιήσεις τον CommandBuilder και να περάσεις στην δεύτερη ή ακόμα καλύτερα την τρίτη λύση που έχει καλύτερο performance. Προσωπικά, ποτέ δεν τον έχω χρησιμοποιήσει και τώρα βλέπω πόσο δίκιο έχουν όλοι αυτοί που έγραφαν στα blogs και τα βιβλία τους ότι είναι μόνο για quick &amp;amp; dirty και όχι production κώδικα.&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&amp;nbsp;&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16521.aspx</link><pubDate>Sun, 10 Sep 2006 23:52:58 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16521</guid><dc:creator>Dimitris Papadimitriou</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16521.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16521</wfw:commentRss><description>&lt;P&gt;&lt;BLOCKQUOTE&gt;&lt;table width="85%"&gt;&lt;tr&gt;&lt;td class="txt4"&gt;&lt;img src="/cs/Themes/default/images/icon-quote.gif"&gt;&amp;nbsp;&lt;strong&gt;gmlogic wrote:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="quoteTable"&gt;&lt;table width="100%"&gt;&lt;tr&gt;&lt;td valign="top" class="txt4"&gt;Λοιπόν !!!!&lt;BR&gt;&lt;BR&gt;Ποιό πάνω έχω τον κώδικα που ανάλογα το DataRowState φτιάχνει&lt;BR&gt;&lt;BR&gt;ο command_builder τα sql querys &lt;BR&gt;&lt;BR&gt;Μπορώ να πάρω το ID μετά το&lt;BR&gt;&lt;BR&gt;da_Sql.InsertCommand = command_builder.GetInsertCommand()&lt;BR&gt;&lt;BR&gt;ή δεν μπορώ?&lt;BR&gt;&lt;BR&gt;Ή πρέπει να αλλάξω τον κωδικά μου και να τα κάνω χειροκίνητα&lt;BR&gt;&lt;BR&gt;ή πρέπει να γυρίσω τα queries σε store procedures ή ......&lt;BR&gt;&lt;BR&gt;ή γιατί πρέπει να μιλάμε για MSSQL2005&lt;BR&gt;&lt;BR&gt;Δέν ξερω :)&lt;BR&gt;&lt;BR&gt;Όπως μς χαρά θα συμβούλευα ένα με λιγώτερη γνώση από μένα&lt;BR&gt;&lt;BR&gt;έτσι θέλω και εγώ να μάθω από κάποιον που ξέρει ποιό πολά από μένα&lt;BR&gt;&lt;BR&gt;γιατί σίγουρα κάποιος ξέρει ποιό πολλά από μένα ......&lt;BR&gt;&lt;BR&gt;Γιώργος Μ.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/BLOCKQUOTE&gt;&lt;/P&gt;
&lt;P&gt;Εγώ το κάνω πολύ καιρό αυτό και με generic κώδικα, όπως περίπου αυτόν που έχεις και εσύ. CommandBuilder και δημιουργία του select statement με loop. Λειτουργεί πολύ καλά τόσο σε sql2000 όσο και σε sql2005.&lt;/P&gt;</description></item><item><title>Απ: Πως θα πάρω το τελευταίο Id πίνακα?</title><link>https://www.dotnetzone.gr:443/cs/forums/thread/16519.aspx</link><pubDate>Sun, 10 Sep 2006 22:51:39 GMT</pubDate><guid isPermaLink="false">2622095e-976c-431a-859e-16783ec7ecd7:16519</guid><dc:creator>gmlogic</dc:creator><slash:comments>0</slash:comments><comments>https://www.dotnetzone.gr:443/cs/forums/thread/16519.aspx</comments><wfw:commentRss>https://www.dotnetzone.gr:443/cs/forums/commentrss.aspx?SectionID=12&amp;PostID=16519</wfw:commentRss><description>Λοιπόν !!!!&lt;br /&gt;
&lt;br /&gt;
Ποιό πάνω  έχω τον κώδικα που ανάλογα το DataRowState φτιάχνει&lt;br /&gt;
&lt;br /&gt;
ο command_builder τα sql querys &lt;br /&gt;
&lt;br /&gt;
Μπορώ να πάρω το ID μετά το&lt;br /&gt;
&lt;br /&gt;
da_Sql.InsertCommand = command_builder.GetInsertCommand()&lt;br /&gt;
&lt;br /&gt;
ή δεν μπορώ?&lt;br /&gt;
&lt;br /&gt;
Ή πρέπει να αλλάξω τον κωδικά μου και να τα κάνω χειροκίνητα&lt;br /&gt;
&lt;br /&gt;
ή πρέπει να γυρίσω τα queries σε store procedures ή ......&lt;br /&gt;
&lt;br /&gt;
ή γιατί πρέπει να μιλάμε για MSSQL2005&lt;br /&gt;
&lt;br /&gt;
Δέν ξερω :)&lt;br /&gt;
&lt;br /&gt;
Όπως μς χαρά θα συμβούλευα ένα με λιγώτερη γνώση από μένα&lt;br /&gt;
&lt;br /&gt;
έτσι θέλω και εγώ να μάθω από κάποιον που ξέρει ποιό πολά από μένα&lt;br /&gt;
&lt;br /&gt;
γιατί σίγουρα κάποιος ξέρει ποιό πολλά από μένα ......&lt;br /&gt;
&lt;br /&gt;
Γιώργος Μ.</description></item></channel></rss>