Datagrid Update Failing - Read only?

  • Thread starter Thread starter Learning SQL Server
  • Start date Start date
L

Learning SQL Server

I am trying to update a datarow via in-place editing from a dataset stored
in session.

When I try to write the new value into the selected row, I always get the
following error : Column [blah] is read-only.

in my UpdateCommand:

dim objDS as DataSet = Ctype(Session("foo"), DataSet)

If IsNothing(objDS) = false then
dim objDT as DataTable = objDS.Tables(0)
dim objRow as DataRow = objDT.Select("Type=" +
e.Item.Cells(1).Text.ToString)

' TERMINATES ON THIS LINE:
objRow(0)("Column1") = CType(e.Item.Cells(2).Controls(0), TextBox).Text
...

End If

I am following the example provided in Dino Esposito's text Building Web
Solutions with ASP.NET and ADO.NET. This doesnt work though. Why?
 
Michael:

The procedure is almost verbatim a code example found on page 115 of the
Dino Esposito text Building Web
Solutions with ASP.NET and ADO.NET. Previously in the page, I created and
stored a DataSet in a session variable (it only contains 8 small rows), and
grab it for use in my UpdateCommand event for the DataGrid (the e argument
is the DataGridCommandEventArgs parameter)

After casting the dataset from the session variable, I am attempting to
access the first row, then each column by name (versus ordinal number). But
that all works; I can see the column names in the Command Immediate window.

It is here that I see one of the attributes for ALL my columns in the
dataset is the following:
Readonly = true

And this is where its breaking. I cannot update the row's columns with the
values I want.





Michael Lang said:
objRow(0) = ...
will set the first columns (0 based) value to whatever.

you could also do:
objRow("Column1") = ...
to set column named "Column1" to whatever.

What are you trying to accomplish with:
objRow(0)("Column1") = ....

and what is this?
CType(e.Item.Cells(2).Controls(0), TextBox).Text
What is "e"? Is this some 3rd party control you bought/made that does not
support DataBinding?

Please clarify...

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)

Learning SQL Server said:
I am trying to update a datarow via in-place editing from a dataset stored
in session.

When I try to write the new value into the selected row, I always get the
following error : Column [blah] is read-only.

in my UpdateCommand:

dim objDS as DataSet = Ctype(Session("foo"), DataSet)

If IsNothing(objDS) = false then
dim objDT as DataTable = objDS.Tables(0)
dim objRow as DataRow = objDT.Select("Type=" +
e.Item.Cells(1).Text.ToString)

' TERMINATES ON THIS LINE:
objRow(0)("Column1") = CType(e.Item.Cells(2).Controls(0), TextBox).Text
...

End If

I am following the example provided in Dino Esposito's text Building Web
Solutions with ASP.NET and ADO.NET. This doesnt work though. Why?
 
objRow(0) = ...
will set the first columns (0 based) value to whatever.

you could also do:
objRow("Column1") = ...
to set column named "Column1" to whatever.

What are you trying to accomplish with:
objRow(0)("Column1") = ....

and what is this?
CType(e.Item.Cells(2).Controls(0), TextBox).Text
What is "e"? Is this some 3rd party control you bought/made that does not
support DataBinding?

Please clarify...
 
If the ReadOnly property is equal to true, then that would give you the
error... So why is ReadOnly equal to true?

When your DataTable is first created, do you have any code that sets any
rows to readonly? How is the table being created?

As a side note, you also may want to consider using DataBinding. Bind your
DataSet directly to the grid, then the updating of each rows values is
automatic. All you have to do is call update on the DataAdapter when done
editing. When you bind a DataSet, the DefaultView (a DataView) is what is
really bound. You can change properties on the DataView to change how the
data can be edited... See "AllowDelete", "AllowEdit", and "AllowNew". It
will also follow any rules on the DataTable, such as not allowing a column
set as read-only to be edited (relates to your problem). You can also
control which columns appear in the grid (See "AutoGenerateColumns"
property).

I can't speak to the quality of the book you mention. I've never seen it.

--
Michael Lang, MCSD

Learning SQL Server said:
Michael:

The procedure is almost verbatim a code example found on page 115 of the
Dino Esposito text Building Web
Solutions with ASP.NET and ADO.NET. Previously in the page, I created and
stored a DataSet in a session variable (it only contains 8 small rows), and
grab it for use in my UpdateCommand event for the DataGrid (the e argument
is the DataGridCommandEventArgs parameter)

After casting the dataset from the session variable, I am attempting to
access the first row, then each column by name (versus ordinal number). But
that all works; I can see the column names in the Command Immediate window.

It is here that I see one of the attributes for ALL my columns in the
dataset is the following:
Readonly = true

And this is where its breaking. I cannot update the row's columns with the
values I want.





Michael Lang said:
objRow(0) = ...
will set the first columns (0 based) value to whatever.

you could also do:
objRow("Column1") = ...
to set column named "Column1" to whatever.

What are you trying to accomplish with:
objRow(0)("Column1") = ....

and what is this?
CType(e.Item.Cells(2).Controls(0), TextBox).Text
What is "e"? Is this some 3rd party control you bought/made that does not
support DataBinding?

Please clarify...

--
Michael Lang, MCSD
See my .NET open source projects
http://sourceforge.net/projects/dbobjecter (code generator)
http://sourceforge.net/projects/genadonet ("generic" ADO.NET)

Learning SQL Server said:
I am trying to update a datarow via in-place editing from a dataset stored
in session.

When I try to write the new value into the selected row, I always get the
following error : Column [blah] is read-only.

in my UpdateCommand:

dim objDS as DataSet = Ctype(Session("foo"), DataSet)

If IsNothing(objDS) = false then
dim objDT as DataTable = objDS.Tables(0)
dim objRow as DataRow = objDT.Select("Type=" +
e.Item.Cells(1).Text.ToString)

' TERMINATES ON THIS LINE:
objRow(0)("Column1") = CType(e.Item.Cells(2).Controls(0), TextBox).Text
...

End If

I am following the example provided in Dino Esposito's text Building Web
Solutions with ASP.NET and ADO.NET. This doesnt work though. Why?
 
Back
Top