Solved

SQLDataAdapter and  computed SQLColumn

Posted on 2006-06-27
3
526 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now