Get Recordset Object from SDE Database (Trying to load Listbox with attribute values)

1413
2
01-10-2012 11:27 AM
ForrestKaye
New Contributor III
So What I'm trying to do is populate a listbox with all the attribute values from a feature layer.  I had accomplished this before when this dataset was in a personal geodatabase but now that it is in an SDE database I cannot use the same objects. 

I am working in VisualStudio 2010 writing in VB.Net.  The original business logic I am referencing was written in VBA for 9.3.  I am now using Arc 10.

The VB.net part for loading the values into the listbox will be simple as long as I have something to loop through that will return a value for a field.


1.  How do I return a recordset from an SDE database?

OR

2.  Is there an easier way to do this?




psudo code of what I'm trying to do:

Dim pRecordset as recordset object

pRecordset.MoveFirst()

Loop pRecordset until End of File
      MyListbox.Add (pRecordset.Fields("myField").Value)
      pRecorset.MoveNext()
0 Kudos
2 Replies
AlexanderGray
Occasional Contributor III
Sounds like you were using ADO recordset to loop through the table.  I suspect you were using the Jet4 (MS Access) driver although that is not the only way to do it.  You can use the oracle client driver with ADO.NET to do a similar thing.  There are many examples online on how to user ADO.NET and oracle, visual studio has lots of tools to do it.  Just beware that if the table or featureclass is versioned, not all the data will be in the base tables, some of it could be scattered in the adds and deletes tables, you would need a versioned view of the table to connect to rather than the table itself.  You can also use arcobjects to do it, opening an sde workspace, getting the table, creating a search cursor, looping through the cursor, retrieving the data from the row.  The ADO.NET way allows you to bind the datatable directly to the control without having the loop through the recordset or cursor which is kind of nice.  I won't give you access to the geometry or do edits on a versioned table (it will let you but it is a bad idea)

Cheers
0 Kudos
ForrestKaye
New Contributor III
Thanks!

The ADO.Net worked great.  It took me some time to figure out the connection string, but its working now.
0 Kudos