Updating a DataColumn after ImportRow

G

Guest

Creating a new dataset from an existing one using ImportRow works just fine
but when I want to modify the DataColumn of the imported rows inside the new
dataset I always get an error saying that the column is read-only ?!?!?!

"System.Data.ReadOnlyException: Column 'start' is read only.
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
at Periods.currentPeriods(Int32 offSet) in
c:\inetpub\wwwroot\WebServices\RossWS\App_Code\RossServices.vb:line 45"


Here part of the code

newDataset = existingDataSet.Clone
Dim copyRows() As DataRow = existingDataSet.Tables(0).Select
Dim periodsTable As DataTable = newDataset.Tables(0)
Dim copyRow As DataRow

For Each copyRow In copyRows
periodsTable.ImportRow(copyRow)
Next

For i = 0 To periodsTable.Rows.Count - 1
periodsTable.Rows(i)("start") = CType(periodsTable.Rows(i)("start"),
DateTime).AddHours(offSet)
periodsTable.Rows(i)("end") = CType(periodsTable.Rows(i)("end"),
DateTime).AddHours(offSet + 24)
Next i

Thanks
 
K

Kevin Yu [MSFT]

Hi Joe,

Thanks for posting your code here. Unfortunately, the code works fine on my
machine. Based on the error message, most probably the "start" and "end"
columns have been set to readonly, so the content of these columns cannot
be modified. Please set a breakpoint after the first for loop and add the
following watches in the watch windows to check if my assumption is true.
Thanks

periodsTable.Columns("start").ReadOnly
periodsTable.Columns("end").ReadOnly

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Effectively, it is read-only but why it is so? I did not set them read-only.
I forgot to mention that the code run inside a Web Service, it is probably
the cause of this behavior ?... I set the read-only flag to false and it
works now. Do you know anything else that run differently in a Web Service?
A good link would be appreciated.

Thanks for your precious help.
 
K

Kevin Yu [MSFT]

Hi Joe,

I don't think it's the problem of the web service. I tried it on my machine
with a web service project and it works fine. It might be set by mistake.
:)

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

I'm the culprit not to say the idiot ! Somewhere far far away, the
datacolumn was set at read-only ..... Sorry for wasting your time and thank
you.
 
K

Kevin Yu [MSFT]

You're welcome, Joe, It was nice to hear that you have had the problem
resolved. Thanks for sharing your experience with all the people here. If
you have any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

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