Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQLDataAdapter and  computed SQLColumn

Posted on 2006-06-27
3
Medium Priority
?
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

660 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