Solved

SQLDataAdapter and  computed SQLColumn

Posted on 2006-06-27
3
535 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

809 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