StrataFrame Forum

"Field" does not belong to table error.

http://forum.strataframe.net/Topic17117.aspx

By Ertan Deniz - 6/17/2008

To handle this error, I've generated FieldAccessing Event for all fields.

But the code that event is fired comes after the code that column is accessed. So, I couldn't handle this condition. I'm trying to catch property access, check column if exist. If column does not exist then column will be added to the table.

Is there alternative way to accomplish tis type of requirement ? 

object loValue;

CompaniesFieldAccessingEventArgs e;

System.String loReturn;

loValue = this.CurrentRow["name"];

if (loValue == DBNull.Value)

{

loReturn = String.Empty;

}

else

{

loReturn = (System.String)loValue;

}

e = new CompaniesFieldAccessingEventArgs(CompaniesFieldNames.name, loReturn);

this.OnFieldPropertyAccessing(this, e);

return (System.String)e.ValueToReturn;

By Trent L. Taylor - 6/17/2008

In our medical app I created a shared method in our of our base classes that I pass over a DataTable, expected field, and field type.  It then ensures that the column exists within the DataTable so that if a query is not performed, yet I have code expecting that field to have been returned from the query, I do not get an error.  This way I can use it across BOs, etc.
By Ertan Deniz - 6/17/2008

I know your method. I couldn't get answer how to use this method. See post below.

http://forum.strataframe.net/Topic15238-6-1.aspx

if you give a new position for FieldAccessing Event. This may solve the situation.

But I need quick way to progress. Where is the place to call the method. (EnsureColumnExist) There must be a central point.

By Ertan Deniz - 6/19/2008

Any comment ?
By Trent L. Taylor - 6/19/2008

This depends entirely on your code.  When I have this issue, and depending on how I may use it, I may include this in the AfterAddNew or the CurrentDataTableRefilled event...it depends entirely on what you are trying to accomplish...I am not sure how to give you a straight answer on this without digging into your code.
By Ertan Deniz - 6/19/2008

As you said, there may be many points to consider. Each of them have to be handled with specific code.

In my case, I want to handle "Object.Property1" case. When I'm trying to use property1, I need to ensure that the field is in the datatable. I couldn't write control logic for each property. Is there a general way that is known? This is my need.

By Ertan Deniz - 6/29/2008

Any Comment ?
By Ertan Deniz - 7/6/2008

I've found a hard way which seems to be infeasible. StrataFrame may solve this internally.

My Solution : In CurrentDataTableReFilled event, I 'm trying to define all the fields that are not included in the query.

Remark : Devexpress Grid tries to reach each property even if is not selected. An exception occurs. So, every column and plus custom fields have to be included in the query. 

By Trent L. Taylor - 7/7/2008

Remark : Devexpress Grid tries to reach each property even if is not selected. An exception occurs. So, every column and plus custom fields have to be included in the query.

Ahhh....yeah, that makes sense.  Glad you found a solution.