Hi,
I'm trying to update a StandaloneTable through the SDK. It is a .dbf file, in my map at the time of running the code. I am using ArcGIS Pro 2.9.
I am getting the error on the row.Store() line. I have tried to update my inspFile.Search(qf) line to inspFile.Search(qf,True), but then I get a "No Overload for method Search take 2 arguments" error. Is this just a 2.9 issue?? If so, is there some other way to update the .dbf that would work in 2.9??
StandaloneTable inspFile = map.GetStandaloneTablesAsFlattenedList().FirstOrDefault(tbl => tbl.Name == GlobalVars.HydInspFile);
QueryFilter qf = new QueryFilter();
qf.SubFields = "FACILITYID";
qf.WhereClause = "FACILITYID = '" + shpFacilityID + "'";
using (RowCursor rowCursor = inspFile.Search(qf))
{
while (rowCursor.MoveNext())
{
using (var row = rowCursor.Current)
{
row["FACILITYID"] = sdeFacilityID;
row.Store();
}
}
}
Solved! Go to Solution.
Your code is very complicated. Try code below:
QueryFilter qf = new QueryFilter();
qf.SubFields = "FACILITYID";
qf.WhereClause = "FACILITYID = '" + shpFacilityID + "'";
var modifyTable = new ArcGIS.Desktop.Editing.EditOperation();
modifyTable.Name = "Update HYDINSP Table";
using (var rowCursor = inspFile.Search(qf))
{
while (rowCursor.MoveNext())
{
using (var row = rowCursor.Current)
{
modifyTable.Modify(row, "FACILITYID", sdeFacilityID);
}
}
}
modifyTable.Execute();
I have made changes of your code directly in community editor and haven't tested it.
Hi,
Standalone table has different Search method parameters than Table or FeatureClass.
More info here:
https://pro.arcgis.com/en/pro-app/2.9/sdk/api-reference/index.html#topic12260.html
What type of error do you get on row Store? System.NotSupportedException or GeodatabaseException?
On ArcGIS Pro 3.1.2 your code works if Search section is included into QueuedTask.Run.
Hi,
Yes, it's all in a QueuedTask.Run.
The error I get is a GeodatabaseException.
So since at 2.9 the Search function doesn't really provide me a way to edit the rows, I guess that I just need to wait until we get 3.x pushed out to us by our IT department.
Maybe your dbf file is locked somewhere else?
Hi,
No, the file is definitely not open by anything else. Only being used in the Pro project.
So I'm trying this on a Pro 3.0 machine, but still getting an error on the row.Store() line. See below. So when you tried this on 3.1 did you make any code changes to what I have above??
As I mentioned I have added QueuedTask.Run and changed field name corresponding my dbf file.
So I got this to work in 3.0. I'll try it in 2.9....my guess is it will work there too.
Not sure why I can't edit that table using a RowCursor though.
Anyways.....
QueryFilter qf = new QueryFilter();
qf.SubFields = "FACILITYID";
qf.WhereClause = "FACILITYID = '" + shpFacilityID + "'";
//Table table = inspFile.GetTable();
var oids = new List<long>();
using (var rowCursor = inspFile.Search(qf))
{
while (rowCursor.MoveNext())
{
using (var row = rowCursor.Current)
{
oids.Add(row.GetObjectID());
}
}
}
var modifyTable = new ArcGIS.Desktop.Editing.EditOperation();
modifyTable.Name = "Update HYDINSP Table";
var tableInsp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
foreach (var oid in oids)
{
tableInsp.Load(inspFile, oid);
tableInsp["FACILITYID"] = sdeFacilityID;
modifyTable.Modify(tableInsp);
}
modifyTable.Execute();
Your code is very complicated. Try code below:
QueryFilter qf = new QueryFilter();
qf.SubFields = "FACILITYID";
qf.WhereClause = "FACILITYID = '" + shpFacilityID + "'";
var modifyTable = new ArcGIS.Desktop.Editing.EditOperation();
modifyTable.Name = "Update HYDINSP Table";
using (var rowCursor = inspFile.Search(qf))
{
while (rowCursor.MoveNext())
{
using (var row = rowCursor.Current)
{
modifyTable.Modify(row, "FACILITYID", sdeFacilityID);
}
}
}
modifyTable.Execute();
I have made changes of your code directly in community editor and haven't tested it.
Yes, that is simpler. Thanks for your help with this!