<?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 Insert Row (VB.NET) in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580894#M82384</link>
    <description>I am pretty new to .net and am having some issues with transactions (I &lt;BR /&gt;
think)...&lt;BR /&gt;
&lt;BR /&gt;
I want to add a row to an existing table.  AutoCAD crashes when I try to &lt;BR /&gt;
open the object for write.  Am I using the transaction improperly?&lt;BR /&gt;
&lt;BR /&gt;
Here is the code I have so far:&lt;BR /&gt;
&lt;BR /&gt;
Dim editor As Editor = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;
Dim pOptions As PromptEntityOptions = New PromptEntityOptions("Select a &lt;BR /&gt;
table: ")&lt;BR /&gt;
Dim pResults As PromptEntityResult = editor.GetEntity(pOptions)&lt;BR /&gt;
Dim tbl As Table&lt;BR /&gt;
Dim trans As Transaction&lt;BR /&gt;
trans = &lt;BR /&gt;
HostApplicationServices.WorkingDatabase().TransactionManager.StartTransaction()&lt;BR /&gt;
tbl = trans.GetObject(pResults.ObjectId, OpenMode.ForWrite)    &amp;lt;----  &lt;BR /&gt;
****crashes here****&lt;BR /&gt;
tbl.InsertRows(1, 1.0, 1)&lt;BR /&gt;
trans.Commit()&lt;BR /&gt;
trans.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the help,&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
Joel Roderick&lt;BR /&gt;
Water Technology, Inc.&lt;BR /&gt;
www.watertechnologyinc.com</description>
    <pubDate>Tue, 14 Mar 2006 20:09:45 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-03-14T20:09:45Z</dc:date>
    <item>
      <title>Insert Row (VB.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580894#M82384</link>
      <description>I am pretty new to .net and am having some issues with transactions (I &lt;BR /&gt;
think)...&lt;BR /&gt;
&lt;BR /&gt;
I want to add a row to an existing table.  AutoCAD crashes when I try to &lt;BR /&gt;
open the object for write.  Am I using the transaction improperly?&lt;BR /&gt;
&lt;BR /&gt;
Here is the code I have so far:&lt;BR /&gt;
&lt;BR /&gt;
Dim editor As Editor = &lt;BR /&gt;
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;
Dim pOptions As PromptEntityOptions = New PromptEntityOptions("Select a &lt;BR /&gt;
table: ")&lt;BR /&gt;
Dim pResults As PromptEntityResult = editor.GetEntity(pOptions)&lt;BR /&gt;
Dim tbl As Table&lt;BR /&gt;
Dim trans As Transaction&lt;BR /&gt;
trans = &lt;BR /&gt;
HostApplicationServices.WorkingDatabase().TransactionManager.StartTransaction()&lt;BR /&gt;
tbl = trans.GetObject(pResults.ObjectId, OpenMode.ForWrite)    &amp;lt;----  &lt;BR /&gt;
****crashes here****&lt;BR /&gt;
tbl.InsertRows(1, 1.0, 1)&lt;BR /&gt;
trans.Commit()&lt;BR /&gt;
trans.Dispose()&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks for the help,&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
Joel Roderick&lt;BR /&gt;
Water Technology, Inc.&lt;BR /&gt;
www.watertechnologyinc.com</description>
      <pubDate>Tue, 14 Mar 2006 20:09:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580894#M82384</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-03-14T20:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Row (VB.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580895#M82385</link>
      <description>This might help.&lt;BR /&gt;
&lt;BR /&gt;
&amp;lt;CommandMethod("AddTableRow")&amp;gt; _&lt;BR /&gt;
Public Shared Sub AddTableRow()&lt;BR /&gt;
Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor&lt;BR /&gt;
Dim db As Database = HostApplicationServices.WorkingDatabase&lt;BR /&gt;
Dim tm As Transaction = db.TransactionManager.StartTransaction()&lt;BR /&gt;
Try&lt;BR /&gt;
Dim res As PromptSelectionResult = ed.GetSelection&lt;BR /&gt;
If res.Status  PromptStatus.OK Then&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
End If&lt;BR /&gt;
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value&lt;BR /&gt;
Dim tempIdArray() As ObjectId&lt;BR /&gt;
tempIdArray = SS.GetObjectIds()&lt;BR /&gt;
Dim tempId As ObjectId&lt;BR /&gt;
Dim tbl As Table&lt;BR /&gt;
For Each tempId In tempIdArray&lt;BR /&gt;
Dim Ent As Entity = CType(tm.GetObject(tempId, OpenMode.ForWrite), Entity)&lt;BR /&gt;
If UCase(Ent.GetType.Name.ToString) = "TABLE" Then&lt;BR /&gt;
tbl = Ent&lt;BR /&gt;
tbl.InsertRows(1, 1.0, 1)&lt;BR /&gt;
End If&lt;BR /&gt;
Next&lt;BR /&gt;
tm.Commit()&lt;BR /&gt;
Catch&lt;BR /&gt;
Finally&lt;BR /&gt;
tm.Dispose()&lt;BR /&gt;
End Try&lt;BR /&gt;
End Sub</description>
      <pubDate>Wed, 15 Mar 2006 13:56:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580895#M82385</guid>
      <dc:creator>Mikko</dc:creator>
      <dc:date>2006-03-15T13:56:13Z</dc:date>
    </item>
    <item>
      <title>Re: Insert Row (VB.NET)</title>
      <link>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580896#M82386</link>
      <description>Look like I needed to lock the document before opening the object...&lt;BR /&gt;
So this line solved the problem:&lt;BR /&gt;
&lt;BR /&gt;
editor.Document.LockDocument()</description>
      <pubDate>Wed, 15 Mar 2006 14:16:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/insert-row-vb-net/m-p/1580896#M82386</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-03-15T14:16:24Z</dc:date>
    </item>
  </channel>
</rss>

