Can't edit a field in a dataset

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

I've created a dataset from a query that returns a column from an
amalgamation of fields in the database.

e.g. SELECT [FirstName] & ' ' & [LastName] AS [FullName] FROM [tblPeople]

However, when I try to modify the value of this column ([FullName], in the
example), I get an error saying it's read only. I can edit the other
columns just fine, but I cannot modify this one.

Is there any way to make the dataset allow me to modify data in this column?
The dataset just contains throwaway data that I'm never going to write back
to the database anyway.

- Don
 
Don,

If this is a typed dataset, the element for the column would have been
automatically marked as read-only if you created the dataset table by
dragging a saved query/view onto the dataset design surface. To fix this,
open the XSD file, select the FullName element in dataset view, and set its
ReadOnly property to false.

If this is not a typed dataset, you should not be seeing this problem. If
so, how are you creating and filling the dataset?

HTH,
Nicole
 
I'm not 100% sure what you mean by "typed dataset", and I don't know
anything about XSD files or dragging queries into dataset design surfaces.
Here is a mockup of the code I used to get the dataset:

----

Dim daTemp As OleDbDataAdapter
Dim dsResult As New DataSet
' mconMainDB is the connection to the database that is already open at this
point

' Build query
strSQL = "SELECT [FirstName],[LastName],[FirstName] & ' ' & [LastName] AS
[FullName] FROM [tblPeople];"

' Create data adapter
daTemp = New OleDbDataAdapter(strSQL, mconMainDB)

' Make sure data adapter gets primary key info when it fills the dataset
daTemp.MissingSchemaAction = MissingSchemaAction.AddWithKey

' Get dataset of appointments
daTemp.Fill(dsResult, strDataTableName)

' Clean up
daTemp.Dispose()

----

I'll be able to edit the [FirstName] and [LastName] columns, but not the
[FullName] column.


- Don




Nicole Calinoiu said:
Don,

If this is a typed dataset, the element for the column would have been
automatically marked as read-only if you created the dataset table by
dragging a saved query/view onto the dataset design surface. To fix this,
open the XSD file, select the FullName element in dataset view, and set its
ReadOnly property to false.

If this is not a typed dataset, you should not be seeing this problem. If
so, how are you creating and filling the dataset?

HTH,
Nicole


Don said:
I've created a dataset from a query that returns a column from an
amalgamation of fields in the database.

e.g. SELECT [FirstName] & ' ' & [LastName] AS [FullName] FROM [tblPeople]

However, when I try to modify the value of this column ([FullName], in the
example), I get an error saying it's read only. I can edit the other
columns just fine, but I cannot modify this one.

Is there any way to make the dataset allow me to modify data in this column?
The dataset just contains throwaway data that I'm never going to write back
to the database anyway.

- Don
 
Sure. This is "by design". Computed expressions are, by default not
updatable.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

Don said:
I'm not 100% sure what you mean by "typed dataset", and I don't know
anything about XSD files or dragging queries into dataset design surfaces.
Here is a mockup of the code I used to get the dataset:

----

Dim daTemp As OleDbDataAdapter
Dim dsResult As New DataSet
' mconMainDB is the connection to the database that is already open at this
point

' Build query
strSQL = "SELECT [FirstName],[LastName],[FirstName] & ' ' & [LastName] AS
[FullName] FROM [tblPeople];"

' Create data adapter
daTemp = New OleDbDataAdapter(strSQL, mconMainDB)

' Make sure data adapter gets primary key info when it fills the dataset
daTemp.MissingSchemaAction = MissingSchemaAction.AddWithKey

' Get dataset of appointments
daTemp.Fill(dsResult, strDataTableName)

' Clean up
daTemp.Dispose()

----

I'll be able to edit the [FirstName] and [LastName] columns, but not the
[FullName] column.


- Don




Nicole Calinoiu said:
Don,

If this is a typed dataset, the element for the column would have been
automatically marked as read-only if you created the dataset table by
dragging a saved query/view onto the dataset design surface. To fix this,
open the XSD file, select the FullName element in dataset view, and set its
ReadOnly property to false.

If this is not a typed dataset, you should not be seeing this problem. If
so, how are you creating and filling the dataset?

HTH,
Nicole


Don said:
I've created a dataset from a query that returns a column from an
amalgamation of fields in the database.

e.g. SELECT [FirstName] & ' ' & [LastName] AS [FullName] FROM [tblPeople]

However, when I try to modify the value of this column ([FullName], in the
example), I get an error saying it's read only. I can edit the other
columns just fine, but I cannot modify this one.

Is there any way to make the dataset allow me to modify data in this column?
The dataset just contains throwaway data that I'm never going to write back
to the database anyway.

- Don
 
Don,

You are using MissingSchemaAction.AddWithKey, which causes the calculated
column to be marked as read-only. Using MissingSchemaAction.Add will avoid
this. However, it might cause some other problems if you are relying on
other information generated through the use of AddWithKey. If this is the
case, you might want to continue using AddWithKey and just mark the column
as writeable prior to the update. e.g. (immediately after filling the
table):

dsResult.Tables.Item(0).Columns.Item(2).ReadOnly = false

HTH,
Nicole



Don said:
I'm not 100% sure what you mean by "typed dataset", and I don't know
anything about XSD files or dragging queries into dataset design surfaces.
Here is a mockup of the code I used to get the dataset:

----

Dim daTemp As OleDbDataAdapter
Dim dsResult As New DataSet
' mconMainDB is the connection to the database that is already open at this
point

' Build query
strSQL = "SELECT [FirstName],[LastName],[FirstName] & ' ' & [LastName] AS
[FullName] FROM [tblPeople];"

' Create data adapter
daTemp = New OleDbDataAdapter(strSQL, mconMainDB)

' Make sure data adapter gets primary key info when it fills the dataset
daTemp.MissingSchemaAction = MissingSchemaAction.AddWithKey

' Get dataset of appointments
daTemp.Fill(dsResult, strDataTableName)

' Clean up
daTemp.Dispose()

----

I'll be able to edit the [FirstName] and [LastName] columns, but not the
[FullName] column.


- Don




Nicole Calinoiu said:
Don,

If this is a typed dataset, the element for the column would have been
automatically marked as read-only if you created the dataset table by
dragging a saved query/view onto the dataset design surface. To fix this,
open the XSD file, select the FullName element in dataset view, and set its
ReadOnly property to false.

If this is not a typed dataset, you should not be seeing this problem. If
so, how are you creating and filling the dataset?

HTH,
Nicole


Don said:
I've created a dataset from a query that returns a column from an
amalgamation of fields in the database.

e.g. SELECT [FirstName] & ' ' & [LastName] AS [FullName] FROM [tblPeople]

However, when I try to modify the value of this column ([FullName], in the
example), I get an error saying it's read only. I can edit the other
columns just fine, but I cannot modify this one.

Is there any way to make the dataset allow me to modify data in this column?
The dataset just contains throwaway data that I'm never going to write back
to the database anyway.

- Don
 
Back
Top