Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 saving computed column to database - urgent!

Author  Topic 

token
Posting Yak Master

133 Posts

Posted - 2006-02-19 : 16:40:39
Hi All,

I have been having a problem that I assume most people would face when making a front-end for a database. I am using Visual C# 2005 and SQL Server 2005.

I added an unbound column called 'Extended' to a table in my Dataset table which performs a calculation for sales tax. The result of my calculation is fine and it displays correctly on my Form.

However, how do I save the value in the computed column back to my database? Essentially I want the value in the 'Extended' computed column to be saved into a column in my database table called 'PriceIncTax'.

Lets say that I don't bother to store the 'Extended' computed column value back to the database i.e. the calculation is done on the Form in real-time. Then if another user on a different machine wants to see how much the price is for a product, his machine won't display the 'PriceIncTax' because it was never stored to the database. It will just return NULL.

I cannot find the answer to my questions anywhere! I've looked in various books and even googled it.... hence I ended up here.

Thanks in advance for your suggestions.

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2006-02-19 : 18:24:24
Well, you'd have to create a column for it in your table. Then use an UPDATE statement to update that column.


Damian
"A foolish consistency is the hobgoblin of little minds." - Emerson
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-19 : 19:53:04
If you are using Stored Procedure to insert / update data into your table, update the calculated value into your PriceIncTax column in the stored procedure.

If not, you can use INSERT or UPDATE trigger to do this.

----------------------------------
'KH'

Time is always against us
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2006-02-19 : 20:07:34
What's that out the window? A VIEW!!!!!

DavidM

Intelligent Design is NOT science.

A front-end is something that tries to violate a back-end.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-19 : 20:17:54
"What's that out the window? A VIEW!!!!!"
Can't see anything out of the window. [wait] Gotta remove the blind. Now i see it. Good VIEW.

----------------------------------
'KH'

Time is always against us
Go to Top of Page

token
Posting Yak Master

133 Posts

Posted - 2006-02-20 : 07:41:20
Ok I think I still don't understand. I have made a very simple database in SQL Server, no stored procedures etc.

The calculation is done in the C# Windows Application form. So when a user types in the 'PriceExTax', it automatically uses my expression to calculate the value of 'PriceIncTax'and displays that value on the Form.

So I now want C# to place the calculated value back into my database so that other users on different machines can view it. The problem is trying to get my Form to save the data back to the database.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2006-02-20 : 17:09:28
Like I said before, use an UPDATE statement.


Damian
"A foolish consistency is the hobgoblin of little minds." - Emerson
Go to Top of Page
   

- Advertisement -