Sunday, January 08, 2006

Update database in OLE DB.

I had a project which will parse the address in one field, and write the parsed out data to the different fields. Today, it seems not working fine. I was quite confused for a while, the return value E_UNEXPECTED didn't return much information even with Dr. MSDN.

To write values into the fields in ATL OLEDB, the SetData() function has be to called firstly, and then the Update() function. The SetData() returns DB_S_ERRORSOCCURRED

According to MSDN:


An error occurred while setting data for one or more columns, but data was successfully set for at least one column. To determine the columns for which data was returned, the consumer checks the status values. For a list of status values that can be returned by this method, see "Status Values Used When Setting Data" in "Status" in Chapter 6: Getting and Setting Data.

So I had to check which field returned the bad value, so I called CDynamicAccessor::GetStatus(), and a memo field returned value (8). I ended up deleting this field out of database, it succeeded.

No comments: