What gives with UpdateSearchedRows?

285
5
08-03-2011 03:20 PM
Highlighted
Regular Contributor
Hello,

I'm using ITable.UpdateSearchedRows and I have a sub field define and my query filter defined so it should only update a  single field on a single row within the given table. However, it's replacing all the fields in the row with null values except the defined sub field. Why is it setting all other fields not included in the sub field to null? I was under the impression that this would just update the specified sub field.

I've included a rough example of my code:

The where clause doesn't contain the field I'm updating but rather includes the fields to find the row where the totallength  should be updated.

ITable tab = GetTable(MyTable);
int totallengthfieldindex = tab.FindField("totallength");
IQueryFilter2 qf2 = new QueryFilterClass();
IRowBuffer buff = tab.CreateRowBuffer();
TotalLength = CalcValue();
qf2.WhereClause = "field = 'myfield' and field2 = " + myfield2 + " and field3 = " + field3value;
qf2.SubFields = "totallength";
buff.set_Value(totallengthfieldindex, TotalLength);
tab.UpdateSearchedRows(qf2, buff);
Reply
0 Kudos
5 Replies
Highlighted
New Contributor III
I'm short with time but SDK states that...
ITable.UpdateSearchedRows description:
This method will edit the rows matching the query filter's constraints.  The  values in each row will be replaced with the corresponding field's value in the  provided row buffer.  The fields being edited should be specified in the query  filter's SubFields property.  If the row buffer contains null values, and the  SubFields property is not properly set, the row's values will be overwritten  with the row buffer's null values.

I don't see
buff.set_Value(index, value);
in your code but i see set_Value for slbuff, maybe you had mistyped.
Hope this can help.

regards Dubravko Antoni�?
Reply
0 Kudos
Highlighted
Regular Contributor
Thanks for the reply.

Yes, my sample code was incorrect. I've made an update to the sample code. However, that wasn't the problem. I read some of the old forum threads on this topic and found it to be a long standing issue. I've changed my update routine completely and it is working now.

G
Reply
0 Kudos
Highlighted
New Contributor III
Any chance someone could post information about what alternative they used? we too are running into issues where trying to update a single field, following all the documentation info, results in ALL fields being set to null.
We are using 10.1 Beta2 and were hoping this was not a beta issue.

Regards,

Eric.
Reply
0 Kudos
Highlighted
New Contributor III
Any chance someone could post information about what alternative they used? we too are running into issues where trying to update a single field, following all the documentation info, results in ALL fields being set to null.
We are using 10.1 Beta2 and were hoping this was not a beta issue.

Regards,

Eric.
Reply
0 Kudos
Highlighted
Regular Contributor
Hi Eric,

I've pretty much stuck with calling row.store() or using an update cursor. I've followed these examples with the exception of the UpdateSearchedRows option, never had good results with it.


// Create a ComReleaser for cursor management.
using(ComReleaser comReleaser = new ComReleaser())
{
     // Use ITable.Update to create an update cursor.
     ICursor updateCursor = table.Update(null, true);
     comReleaser.ManageLifetime(updateCursor);
     // Find the positions of the fields used to get and set values.
     int firstNameIndex = table.FindField("FirstName");
     int lastNameIndex = table.FindField("LastName");
    int emailIndex = table.FindField("Email");
     IRow row = null;
     while ((row = updateCursor.NextRow()) != null)
     {       
       // Get the first and last names.
       String firstName = Convert.ToString(row.get_Value(firstNameIndex));
        String lastName = Convert.ToString(row.get_Value(lastNameIndex));
       // Append the first letter of the first name and the entire last name with
       // an "at" symbol and the email domain to make an email address.
       String emailAddress = String.Concat(firstName[0], lastName, "@MyCompanyName.com");
       row.set_Value(emailIndex, emailAddress);
       updateCursor.UpdateRow(row);    
    }
}


G
Reply
0 Kudos