"Cannot change ReadOnly property of the expression column"

A

Aaron Smith

Ok. I have a dataset that has multiple tables in it. In one of the child
tables, I have a column that I added to the DataSet (Not in the
DataSource). This column does not need to be stored in the data on the
datasource. It simply gets the first name and last name of an instructor
and displays it in the grid. I have two major problems.... One, it
doesn't display in the column until the row is saved, (Even after
calling a refresh on the grid) and two, I am getting a Cannot change
ReadOnly property of the expression column error message when I try to
update the datasource. I found a lot of confusing information that dealt
with the column updating the datasource, etc etc. The column is in none
of the commands attached to the data adapters.

For the column refresh problem, I added code to manually fill in that
field when leaving a previous column and that seemed to work, however,
it doesn't always show when doing a refresh. I have to navigate back to
that column in order to see it.

Any ideas on either problem?
Aaron
 
C

Chris, Master of All Things Insignificant

How did you add the column to the dataset? You added it to the Table? Can
you post some simplified code that shows the problem?

Chris
 
A

Aaron Smith

I just added it to the Dataset Schema and then set the expression in the
new procedure of the form...

CoursesDS1.InstClasses.FullNameColumn.Expression =
"Parent(InstructorsInstClasses).First_Name + ' ' +
Parent(InstructorsInstClasses).Last_Name"

Thats the expression...

If that is the only line of code in there, and I don't manually set the
value, it still does not work.. I still get the same message. Should I
remove that column from the schema and manually create the column and
add it to the table?? I think I will try that while waiting for other
suggestions.

Aaron

Chris said:
How did you add the column to the dataset? You added it to the Table? Can
you post some simplified code that shows the problem?

Chris
 
A

Aaron Smith

I'm still getting this error, does anyone have any more ideas? I removed
the field from the schema and manually add it and I still get the error
message. The record actually saves, but this error just pops up.. If
there a way to turn error checking off for certain fields? Is it just a
property I am not setting?

Aaron said:
I just added it to the Dataset Schema and then set the expression in the
new procedure of the form...

CoursesDS1.InstClasses.FullNameColumn.Expression =
"Parent(InstructorsInstClasses).First_Name + ' ' +
Parent(InstructorsInstClasses).Last_Name"

Thats the expression...

If that is the only line of code in there, and I don't manually set the
value, it still does not work.. I still get the same message. Should I
remove that column from the schema and manually create the column and
add it to the table?? I think I will try that while waiting for other
suggestions.

Aaron
 
A

Aaron Smith

I fixed this problem. The solution is quite simple. Whenever you call
Update on the dataadapter, just remove the expression and then add it
back after the update is finished:

Dim dc As DataColumn = DataSet.Table.Columns.Item("ExpCol")
Dim exp As String = dc.Expression
dc.Expression = ""
Try
DataAdapter.Update(DataSet, "Table")
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message(),"Error")
Finally
dc.Expression = exp
End Try

I tried to just remove the whole column, then add it back in, but for
some reason I was getting an error message that the column wasn't a
datacolumn or datarelation, so I simplified...
 
G

Guest

I was running into the same problem and, based on wht I learned here, decided
to catch and ignore the exception.

Alternative to manually accepting changes at the table level would be to
accept all changes in the dataset at the end of the updates.

Carl

Here is the code snippet:


Try
Me.sdaOrders.Update(inDS.Orders.Select("", "", _
DataViewRowState.Added Or
DataViewRowState.ModifiedCurrent))
Catch RO_exception As Data.ReadOnlyException
' do nothing, need to catch it for the expression column
' DO NOT Accept changes here, more changes to be saved later!
End Try
' can add, change, and delete because no subordinate tables
Me.sdaOrderPayments.Update(inDS.OrderPayments)

' only add or modify, can't delete because there are subordinate
tables
Me.sdaOrderDetails.Update(inDS.OrderDetails.Select("", "", _
DataViewRowState.Added Or DataViewRowState.ModifiedCurrent))
' can add, change, and delete because no subordinate tables
Me.sdaOrderMiscCharges.Update(inDS.OrderDetailMiscCharges)
' only add or modify, can't delete because there are subordinate
tables

Me.sdaOrderDetailComponents.Update(inDS.OrderDetailComponents.Select("", "", _
DataViewRowState.Added Or DataViewRowState.ModifiedCurrent))
' can add, change, and delete because no subordinate tables

Me.sdaOrderDetailComponentSpeficiations.Update(inDS.OrderDetailComponentSpecifications)

' now pick up the deletes, from the bottom up
Me.sdaOrderDetailComponents.Update(inDS.OrderDetailComponents)
Me.sdaOrderDetails.Update(inDS.OrderDetails)
Try
Me.sdaOrders.Update(inDS.Orders)
Catch RO_exception As Data.ReadOnlyException
' accept changes manually and continue
inDS.Orders.AcceptChanges()
End Try
 
G

Guest

OK, well, that solution wasn't quite as solid as I thought yesterday. I was
just hiding the problem. After more research apparently this is a known bug
since 2002 although I can find no reference to it when searching the MS KB.
There is a nice little writeup on it with workarounds at www.falafel.com/flogs

I chose to drop the expression columns, do the update, and restore them.
Simply setting the expression to empty or Nothing raised an "instance of
object not set" exception. Still needs more testing but it appears to get
around the problem. Since I have a separate data access layer I do it at
that level avoiding the problems (I think!) with dropping the columns and
databinding.

Carl

Here is a simple code snippet:

' save expression columns and delete them out so updates will go
through
Dim dcLastNameFirstExp As DataColumn =
inDS.Customer.Columns("LastNameFirst")
Dim dcCityStateZipExp As DataColumn =
inDS.Customer.Columns("CityStateZip")
inDS.Customer.Columns.Remove("LastNameFirst")
inDS.Customer.Columns.Remove("CityStateZip")

' save customer changes and additions
Me.sdaCustomer.Update(inDS.Customer.Select("", "", _
DataViewRowState.Added Or DataViewRowState.ModifiedCurrent))
' save all phone number changes, including deletes
Me.sdaPhoneNumber.Update(inDS.CustomerPhoneNumber)
' process customer deletes
Me.sdaCustomer.Update(inDS.Customer)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top