Solved

SQLDataAdapter and  computed SQLColumn

Posted on 2006-06-27
3
536 Views
Last Modified: 2012-06-27
Hi,

I have the following issue:

I have a SQL-Server 2000
I have a Table with a computed column (interestValue which calculates interestRate * value)
I'm using databinding on a winform
I'm using the sqlDataAdapter with CommandBuilder

I want to add a new row to the datatable
I want to save these row to the database

My problem is:

I cannot save this row to the database because the sqldataadapter says that computed columns are not updateable. That's quite correct. How can I tell my datatable that he sould not save/change my computed column?

I think the failure is that, when I add a new row to the datatable, the computed table gets a default value.

Please help
Thanks

Sascha
0
Comment
Question by:srexp
  • 2
3 Comments
 
LVL 41

Expert Comment

by:graye
ID: 16993874
If you're using the CommandBuilder feature,  you must give it an altered SelectCommand that doesn't contain that field so that the CommandBuilder will create the insert, update, and delete commands without that field.   Or, you could just edit the SQL commands by hand...

It'd look something like this:

' return all columns
cmd.SelectCommand.CommandText = "Select * from SomeTable"
da.Fill(SomeDataTable)

' a prototype select statement with the computed column missing
cmd.SelectCommand.CommandText = "Select Larry, Moe, Curly from SomeTable"
' create the Insert, Update and Delete commands for me...
SomeCommandBuilder.RefreshSchema()

da.Update(SomeDataTable)
0
 

Author Comment

by:srexp
ID: 16994008
Thanks for your answer. How can i programmatically figure out, if a column is computed. the datacolumn does not have such a property.
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 16995759
just wondering...

Try adding the following to the DataAdapter prior to the fill()

DataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

Then check the DataColumn's Expression property

... it *might* show the computed column's "formula"....
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question