Connecting Tech Pros Worldwide Help | Site Map

"Cannot change ReadOnly property of the expression column"

Aaron Smith
Guest
 
Posts: n/a
#1: Nov 21 '05
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
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Chris, Master of All Things Insignificant
Guest
 
Posts: n/a
#2: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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

"Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .[color=blue]
> 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
> --
> ---
> Aaron Smith
> Remove -1- to E-Mail me. Spam Sucks.[/color]


Aaron Smith
Guest
 
Posts: n/a
#3: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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, Master of All Things Insignificant wrote:[color=blue]
> 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
>
> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
> news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .
>[color=green]
>>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
>>--
>>---
>>Aaron Smith
>>Remove -1- to E-Mail me. Spam Sucks.[/color]
>
>
>[/color]


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Aaron Smith
Guest
 
Posts: n/a
#4: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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 Smith wrote:[color=blue]
> 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, Master of All Things Insignificant wrote:
>[color=green]
>> 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
>>
>> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
>> news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .
>>[color=darkred]
>>> 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
>>> --
>>> ---
>>> Aaron Smith
>>> Remove -1- to E-Mail me. Spam Sucks.[/color]
>>
>>
>>
>>[/color]
>
>[/color]


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Aaron Smith
Guest
 
Posts: n/a
#5: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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...

Aaron Smith wrote:[color=blue]
> 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 Smith wrote:
>[color=green]
>> 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, Master of All Things Insignificant wrote:
>>[color=darkred]
>>> 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
>>>
>>> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
>>> news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .
>>>
>>>> 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
>>>> --
>>>> ---
>>>> Aaron Smith
>>>> Remove -1- to E-Mail me. Spam Sucks.
>>>
>>>
>>>
>>>
>>>[/color]
>>
>>[/color]
>
>[/color]


--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
clorentson
Guest
 
Posts: n/a
#6: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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.OrderDetailMisc Charges)
' only add or modify, can't delete because there are subordinate
tables

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

Me.sdaOrderDetailComponentSpeficiations.Update(inD S.OrderDetailComponentSpecifications)

' now pick up the deletes, from the bottom up
Me.sdaOrderDetailComponents.Update(inDS.OrderDetai lComponents)
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

"Aaron Smith" wrote:
[color=blue]
> 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...
>
> Aaron Smith wrote:[color=green]
> > 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 Smith wrote:
> >[color=darkred]
> >> 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, Master of All Things Insignificant wrote:
> >>
> >>> 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
> >>>
> >>> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
> >>> news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .
> >>>
> >>>> 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
> >>>> --
> >>>> ---
> >>>> Aaron Smith
> >>>> Remove -1- to E-Mail me. Spam Sucks.
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>[/color]
> >
> >[/color]
>
>
> --
> ---
> Aaron Smith
> Remove -1- to E-Mail me. Spam Sucks.
>[/color]
clorentson
Guest
 
Posts: n/a
#7: Nov 21 '05

re: "Cannot change ReadOnly property of the expression column"


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)


"clorentson" wrote:
[color=blue]
> 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.OrderDetailMisc Charges)
> ' only add or modify, can't delete because there are subordinate
> tables
>
> Me.sdaOrderDetailComponents.Update(inDS.OrderDetai lComponents.Select("", "", _
> DataViewRowState.Added Or DataViewRowState.ModifiedCurrent))
> ' can add, change, and delete because no subordinate tables
>
> Me.sdaOrderDetailComponentSpeficiations.Update(inD S.OrderDetailComponentSpecifications)
>
> ' now pick up the deletes, from the bottom up
> Me.sdaOrderDetailComponents.Update(inDS.OrderDetai lComponents)
> 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
>
> "Aaron Smith" wrote:
>[color=green]
> > 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...
> >
> > Aaron Smith wrote:[color=darkred]
> > > 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 Smith wrote:
> > >
> > >> 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, Master of All Things Insignificant wrote:
> > >>
> > >>> 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
> > >>>
> > >>> "Aaron Smith" <thespirit-1-@smithcentral.net> wrote in message
> > >>> news:bbnwd.947$1o1.14@newssvr19.news.prodigy.com.. .
> > >>>
> > >>>> 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
> > >>>> --
> > >>>> ---
> > >>>> Aaron Smith
> > >>>> Remove -1- to E-Mail me. Spam Sucks.
> > >>>
> > >>>
> > >>>
> > >>>
> > >>>
> > >>
> > >>
> > >
> > >[/color]
> >
> >
> > --
> > ---
> > Aaron Smith
> > Remove -1- to E-Mail me. Spam Sucks.
> >[/color][/color]
Closed Thread