Solved

SQLDataAdapter and  computed SQLColumn

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

627 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