Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to load features into ArcSDE without using ArcObjects, and using SQL from my .NET Application instead.

I have followed the answers given in this question: Is it possible to load features into ArcSDE without using ArcObjects?

The Only problem, is that in the insert SQL Statement, I have to give the objectID, like this:

INSERT INTO [mydatabase].[dbo].[DATAPTS]
           ([OBJECTID],[tor]
           ,[value]
           ,[SHAPE])
     VALUES
           (1,dateadd(hour, 11, dateadd(dayofyear, 62 - 1, dateadd(year, 2013 - 1900, 0)))
           ,0.23654
           ,geometry::STGeomFromText('POINT (30000 198572)', 32643))
GO

Is this the best way to give the object Id?
Or is there any way to get SQL Server to auto increment this field?

(The second looks impossible, because the Featureclass created by ArcGIS in the SDE, has int as the OBJECTID, and you can't Add identity to an existing column)

share|improve this question
add comment

1 Answer 1

Get the max ObjectID value from the table first, add one to that and use the result in your insert statement.

values ((select MAX(OBJECTID) from [dbo].[DATAPTS]) + 1 , ...

DG

share|improve this answer
    
That is exactly what I am doing now; But I wonder if there is a better way to do this. –  Devdatta Tengshe May 14 '13 at 6:43
    
As you stated, the feature table does not auto increment the ObjectID field so you have to manually set a unique value when you insert in SQL. The MAX aggregate is a very fast SQL operation especially since OBJECTID is a primary indexed key. I think in ArcGIS Desktop, the ArcObjects code that adds records to a feature class is doing a similar operation. I would think the SQL MAX aggregate would be faster than ArcObjects at determining the max value. –  DLG May 14 '13 at 7:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.