<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DataTable AppendRow fail in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270103#M58148</link>
    <description>&lt;P&gt;I have never worked wit DataTable before&lt;/P&gt;&lt;P&gt;Just at the quick glance&lt;/P&gt;&lt;P&gt;Use Try..Catch to handle errors easily&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;       public void CommitSettings() 	
       {	

               Document doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;	

               Database db = doc.Database; 	

               Editor ed=doc.Editor;		

            using    (Transaction myT = db.TransactionManager.StartTransaction())	
            {	
               DataTable table = null;	
               try	
               {	

                  //Your rest code here	
            
                   myT.Commit();	


                  // myT.Dispose();	
               }	
               catch (System.Exception ex)	
               {
                   ed.WriteMessage("\nReason of Error: {0}\nTrace: {1}",ex.Message,ex.StackTrace);	
               }	
               finally	
               {	
                   for (int r = 0; r &amp;lt; table.NumRows; r++)	
                   {	
                       string strrow = "";	

                       for (int c = 0; c &amp;lt; table.NumColumns; c++)	
                       {	

                           DataCell cl = table.GetCellAt(r, c);	

                           strrow = strrow + "\t" + cl.Value.ToString();	

                       }	
                       ed.WriteMessage("\n\t==&amp;gt;{0}", strrow);	
                   }	
                   if (table != null)	
                       table.Dispose();	
               }	
            }	
           } 	

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After your code will be finished check your table&lt;/P&gt;&lt;P&gt;by typing this expression in the command line:&lt;/P&gt;&lt;P&gt;(entget (cdr (last (entget (cdr (assoc 330 (dictnext (namedobjdict) "&lt;STRONG&gt;DuctTapeEntryStringHere&lt;/STRONG&gt;")))))))&lt;/P&gt;&lt;P&gt;just change DuctypeEntry string in this expresion&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2011 21:30:44 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2011-12-20T21:30:44Z</dc:date>
    <item>
      <title>DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3246260#M58146</link>
      <description>&lt;P&gt;.Net, C-Sharp:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got configuration data that I'd like to save in a DataTable, but when I load the data into a DataCellCollection, append that to a DataTable, then check the number of cells in the appended row, it looks like the row loses all the cells that it had.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Partial code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;namespace GIS_DuctTape
{
	using System;
	using System.Collections.Generic;
	using System.Diagnostics;
	using Autodesk.AutoCAD.DatabaseServices;

	public class DuctTapeConfig
	{
		//...
		public DataTable MakeTable() {
			Debug.WriteLine("DuctTapeConfig#MakeTable() - start"); 
			DataTable table = new DataTable();

			table.AppendColumn(CellType.CharPtr, "SourceFile");
			table.AppendColumn(CellType.CharPtr, "Feature");
			table.AppendColumn(CellType.CharPtr, "AttributeFields");
			table.AppendColumn(CellType.CharPtr, "Layer");

			foreach(FeatureInfo fi in FeaturesList) {
				DataCellCollection row = fi.AsDataTableRow;
				Debug.WriteLine("  input row has " + row.Count + " cells." );
				table.AppendRow(row, false);
				Debug.WriteLine("  table row " + (table.NumRows - 1) + " has " + table.GetRowAt(table.NumRows - 1).Count + " cells." );
			}

			Debug.Flush();
			return table;
		}
		//...
	}
}&lt;/PRE&gt;&lt;P&gt;Log file output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DuctTapeConfig#MakeTable() - start
  input row has 4 cells.
  table row 0 has 0 cells.&lt;/PRE&gt;&lt;P&gt;Any idea what's wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2011 15:00:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3246260#M58146</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-01T15:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3269451#M58147</link>
      <description>&lt;P&gt;No ideas from anyone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to try to eliminate some things, I've re-written the code:&lt;/P&gt;&lt;PRE&gt;  public void CommitSettings() {
   Debug.WriteLine("DuctTapeConfig#CommitSettings()");
   if (AmChanged) {
    Debug.Assert(FeaturesList.Count &amp;gt; 0, "  Empty features list.");

    Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
    OpenCloseTransaction myT = db.TransactionManager.StartOpenCloseTransaction();
    DataTable table = null;

    try {
     DBDictionary NamedObjsDict = (DBDictionary)myT.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
     if (NamedObjsDict.Contains(DuctTapeEntry)) {
      table = (DataTable)myT.GetObject(NamedObjsDict.GetAt(DuctTapeEntry), OpenMode.ForWrite);
      Debug.WriteLine("  found table: column count is " + table.NumColumns);
      if (table.NumColumns &amp;lt; 4) {
       NamedObjsDict.Remove(DuctTapeEntry);
       Debug.WriteLine("  Removed table from Named Objects Dictionary");
      }
      else { while (table.NumRows &amp;gt; 0) table.RemoveRowAt(0); }
     } else {
      table = new DataTable();
      table.AppendColumn(CellType.CharPtr, "SourceFile");
      table.AppendColumn(CellType.CharPtr, "Feature");
      table.AppendColumn(CellType.CharPtr, "AttributeFields");
      table.AppendColumn(CellType.CharPtr, "Layer");
      NamedObjsDict.SetAt(DuctTapeEntry, table);
      myT.AddNewlyCreatedDBObject(table, true/*add*/);
      Debug.Assert((table.NumColumns == 4), "New data table is corrupted");
     }
     Debug.Assert(table.IsWriteEnabled, "Data table is not write enabled");
     foreach(FeatureInfo fi in FeaturesList) {
      DataCellCollection row = fi.AsDataTableRow; int nRowAdded = -1;
      Debug.WriteLine("  Before append, row has " + row.Count + " cells." );
      table.AppendRow(row, true); nRowAdded = table.NumRows - 1;
      row = table.GetRowAt(nRowAdded);
      Debug.WriteLine("  After append, row has " + row.Count + " cells.");
     }
    } finally {
     myT.Commit();
     myT.Dispose();
     if (table != null) table.Dispose();
     Debug.Flush();
    }
   }
  }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Log file results:&lt;/P&gt;&lt;PRE&gt;DuctTapeConfig#CommitSettings()
  found table: column count is 4
  Before append, row has 4 cells.
  After append, row has 0 cells.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 15:35:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3269451#M58147</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-20T15:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270103#M58148</link>
      <description>&lt;P&gt;I have never worked wit DataTable before&lt;/P&gt;&lt;P&gt;Just at the quick glance&lt;/P&gt;&lt;P&gt;Use Try..Catch to handle errors easily&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;       public void CommitSettings() 	
       {	

               Document doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;	

               Database db = doc.Database; 	

               Editor ed=doc.Editor;		

            using    (Transaction myT = db.TransactionManager.StartTransaction())	
            {	
               DataTable table = null;	
               try	
               {	

                  //Your rest code here	
            
                   myT.Commit();	


                  // myT.Dispose();	
               }	
               catch (System.Exception ex)	
               {
                   ed.WriteMessage("\nReason of Error: {0}\nTrace: {1}",ex.Message,ex.StackTrace);	
               }	
               finally	
               {	
                   for (int r = 0; r &amp;lt; table.NumRows; r++)	
                   {	
                       string strrow = "";	

                       for (int c = 0; c &amp;lt; table.NumColumns; c++)	
                       {	

                           DataCell cl = table.GetCellAt(r, c);	

                           strrow = strrow + "\t" + cl.Value.ToString();	

                       }	
                       ed.WriteMessage("\n\t==&amp;gt;{0}", strrow);	
                   }	
                   if (table != null)	
                       table.Dispose();	
               }	
            }	
           } 	

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After your code will be finished check your table&lt;/P&gt;&lt;P&gt;by typing this expression in the command line:&lt;/P&gt;&lt;P&gt;(entget (cdr (last (entget (cdr (assoc 330 (dictnext (namedobjdict) "&lt;STRONG&gt;DuctTapeEntryStringHere&lt;/STRONG&gt;")))))))&lt;/P&gt;&lt;P&gt;just change DuctypeEntry string in this expresion&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 21:30:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270103#M58148</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-20T21:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270159#M58149</link>
      <description>&lt;P&gt;Thanks for the response.&amp;nbsp; I added the catch(System.Exception err){ } block as suggested, compiled and ran the app.&amp;nbsp; As written, the code does not throw an exception, seemingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the Lisp code suggested, and confirmed that the table was inserted properly into the Named Objects Dictionary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From other testing, the table itself is added properly, and it&amp;nbsp;has the row that was added - but the row doesn't have any cells in it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most perplexing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:17:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270159#M58149</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-20T22:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270169#M58150</link>
      <description>&lt;P&gt;&amp;nbsp;I just added dummy values this way it's working on my end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;              for (int i = 0; i &amp;lt; 9; i++)
                   {
                       //DataCellCollection row = fi.AsDataTableRow;
                       DataCellCollection row = new DataCellCollection();
                       for (int a = 0; a &amp;lt; 4; a++)
                       {
                           DataCell cl = new DataCell(); //= new Cell();
                           cl.SetString("Row" + (i + 1).ToString()+"Col" + (a + 1).ToString());
                           row.Add(cl);
                       }
                       int nRowAdded = -1;
                       //  Debug.WriteLine(" Before append, row has " + row.Count + " cells.");
                       table.AppendRow(row, false);
                       nRowAdded = table.NumRows - 1;
                        row = table.GetRowAt(nRowAdded);
                         //Debug.WriteLine(" After append, row has " + row.Count + " cells."); 
                   }&lt;/PRE&gt;&lt;P&gt;Remove&amp;nbsp;all ugly Debugs from there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2011 22:23:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3270169#M58150</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2011-12-20T22:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3777707#M58151</link>
      <description>&lt;P&gt;Hello Hallex,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you worked with DataTable since?&lt;BR /&gt;&lt;BR /&gt;I just tried working with DataTable today and I experienced the exact behaviour.&lt;/P&gt;&lt;P&gt;Row being added but the DataCellCollection (Cells) that were added to it do not persist.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 20:57:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3777707#M58151</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-11T20:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3777935#M58152</link>
      <description>&lt;SPAN style="font-family:Verdana; color:#000000; font-size:10pt;"&gt;&lt;/SPAN&gt;&lt;DIV&gt;I never got it to work.&amp;nbsp; In checking further through the AutoDesk support system, their trouble shooting software determined that my employer's AutoCAD version had not been updated with the latest service pack.&amp;nbsp; I reported that to our IT department, and they apparently decided that installing the service pack would cause more trouble than what it might or might not fix - I never heard back from them.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;The application I was going to use the data table for was never more than a personal idea of mine, and in fact I've since retired.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;Sorry, can't help you much.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Feb 2013 04:02:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3777935#M58152</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-12T04:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: DataTable AppendRow fail</title>
      <link>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3778254#M58153</link>
      <description>&lt;P&gt;Which AutoCAD version were you using? I'm using 2010 with no service pack. I think I'll try, at some point with another version. I could really make use of a data table but there are ways around this.&lt;/P&gt;&lt;P&gt;May I say congratulations on your retirement? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;AutoCAD is fun as long as there are problems to solve &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Have a good year!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 13:58:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/datatable-appendrow-fail/m-p/3778254#M58153</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-12T13:58:27Z</dc:date>
    </item>
  </channel>
</rss>

