Select to view content in your preferred language

Can't create row buffer

2843
5
11-10-2010 12:05 PM
ChrisAnderson
New Contributor II
Does anyone know of a reason why i'm getting the following error?

Error HRESULT E_FAIL has been returned from a call to a COM component.

I created an inMemory table using an inMemory workspace and am trying to add rows to that table. But i get the above error when i hit the following line of code (VB.NET).

Dim rowBuffer As ESRI.ArcGIS.Geodatabase.IRowBuffer = tempTable.CreateRowBuffer
0 Kudos
5 Replies
DuncanHornby
MVP Notable Contributor
Chris,

Below is a VBA script I knocked up to test the whole in_memory workspace thing. I know it's not .Net but this should pretty much port into your code and gives you an idea of what worked for me?

Duncan

Public Sub InMemoryExample()
 ' Description: Sample code showing how an in memory table can be created
 
 ' Create Workspacefactory
 Dim pWorkSpaceFactory As IWorkspaceFactory2
 Set pWorkSpaceFactory = New InMemoryWorkspaceFactory
 
 ' Create Workspace
 Dim pWorkspaceName As IWorkspaceName2
 Set pWorkspaceName = pWorkSpaceFactory.Create("", "MyInMemoryWorkspace", Nothing, 0)
 
 ' Get a handle on Name
 Dim pName As IName
 Set pName = pWorkspaceName
 
 ' Get a handle on FeatureWorkspace
 Dim pFeatureWorkspace As IFeatureWorkspace
 Set pFeatureWorkspace = pName.Open
 
 ' Now create a fields object and add some fields to it
 
 ' Create Fields object and set the number of fields
 Dim pFields As IFields
 Set pFields = New Fields
 Dim pFieldsEdit As IFieldsEdit
 Set pFieldsEdit = pFields
 pFieldsEdit.FieldCount = 2
 
 ' Create objectID field
 Dim pField As IField
 Set pField = New Field
 Dim pFieldEdit As IFieldEdit
 Set pFieldEdit = pField
 With pFieldEdit
 .Name = "OBJECTID"
 .Type = esriFieldTypeOID
 End With
 Set pFieldsEdit.Field(0) = pField
 
 ' Create Type field
 Set pField = New Field
 Set pFieldEdit = pField
 With pFieldEdit
 .Editable = True
 .Name = "VegType"
 .Type = esriFieldTypeString
 .Length = 4
 .AliasName = "Vegetation Type Code"
 End With
 Set pFieldsEdit.Field(1) = pField
 
 ' Create Table
 Dim pTable As ITable
 Set pTable = pFeatureWorkspace.CreateTable("MyInMemTable", pFields, Nothing, Nothing, "")
 
 ' Create a sample row and add data
 Dim pRow As IRow
 Set pRow = pTable.CreateRow
 With pRow
 .Value(1) = "WOOD"
 .Store
 End With
 
 ' Add table to map document
 Dim pMXD As IMxDocument
 Set pMXD = ThisDocument
 Dim pMap As IMap
 Set pMap = pMXD.FocusMap
 Dim pStandAloneTableCollection As IStandaloneTableCollection
 Set pStandAloneTableCollection = pMap
 Dim pStandAloneTable As IStandaloneTable
 Set pStandAloneTable = New StandaloneTable
 Set pStandAloneTable.Table = pTable
 pStandAloneTableCollection.AddStandaloneTable pStandAloneTable
 pMXD.UpdateContents
End Sub
0 Kudos
ChrisAnderson
New Contributor II
Can you try it with an insert cursor instead to see if it works for you. I'd prefer to use an insert cursor because it is more efficient and i have a whole lot of records to add. According to the esri help the insert cursor is quicker than using the create row command each time. Thanks, i'll use the create row way to see if i get the same error or not.
0 Kudos
DuncanHornby
MVP Notable Contributor
Chris,

I replaced the code:

 Dim pRow As IRow
 Set pRow = pTable.CreateRow
 With pRow
    .Value(1) = "WOOD"
    .Store
 End With


with:

Dim pRowBuffer As IRowBuffer
 Dim pCursor As ICursor
 Set pCursor = pTable.Insert(True)
 Set pRowBuffer = pTable.CreateRowBuffer
 pRowBuffer.Value(1) = "WOOD"
 pCursor.InsertRow pRowBuffer


and this worked without a problem.

Duncan
0 Kudos
ChrisAnderson
New Contributor II
i've tried both ways and still get the same error. I'm using an editor license so i know that isn't it. it always fails at the line where i create the rowbuffer.
0 Kudos
DuncanHornby
MVP Notable Contributor
Chris,

OK I guess you need to check that your table is actually being created correctly? Try adding the table to the mxd but don't add anything to it. This will hopefully confirm that your code is creating a valid table ready to be populated with rows. I would even try to add a row manually just to make sure it's not being file locked or something.

Duncan
0 Kudos