?
Solved

Calculating Tax (VAT) in ASP.NET db's

Posted on 2005-03-09
23
Medium Priority
?
1,033 Views
Last Modified: 2012-08-14
Hi there,

I'm looking to create a variable for VAT in a webpage which calls from a db. The itemPrice is the the plain value, then I wanted a vat value which calculates the UK VAT value (17.5%) and then adds it as a second option. I'll also need a third option which adds the two together.

Here's a glimpse of what I have below.

Any ideas?

Thanks in advance.


<ItemTemplate>

vat = (<%#Container.DataItem("ItemPrice")%> * 0.175)

    £<%#Container.DataItem("ItemPrice")%>
    <br>
    £<%=vat%>
</ItemTemplate>
0
Comment
Question by:DanBAtkinson
[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
  • 11
  • 11
23 Comments
 
LVL 5

Expert Comment

by:fahimnxb
ID: 13495087
Dear DanBAtkinson,

There are many ways to calculate vat. The approach you are using is not a very good approach and probably produce an error. Its better if you calculate vat in the db, like in stored procedure and total it there too.
A second way is calculate vat in code behind file rather than rendring it in HTML through item template.

Regards,
Me
0
 

Author Comment

by:DanBAtkinson
ID: 13495430
Could you please explain how to do it in the db or calculate it behind the file then please?
0
 
LVL 9

Expert Comment

by:Type25
ID: 13495594
If you want to caluclate it in the DB, create another column and as the formula write: [ItemPrice] * 17.5%

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:Type25
ID: 13495613
Alternatively, use inline SQL:

SELECT [ItemPrice] * 17.5 AS ItemPriceIncVat FROM YourTable
0
 
LVL 9

Expert Comment

by:Type25
ID: 13495619
That should be  

SELECT CAST([ItemPrice] * 17.5 AS decimal) AS ItemPriceIncVat FROM YourTable...
0
 

Author Comment

by:DanBAtkinson
ID: 13495926
Thankyou.

I can't add another column in the table as that would result in a self-referential calculation. Calculating something inside the table.

Going with the SQL, I currently have this then...


 sub Page_Load
  dim dbconn,sql,dbcomm,dbread
  dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("admin.mdb"))
  dbconn.Open()
  sql="SELECT * FROM tblProducts"
  SELECT CAST([ItemPrice] * 17.5 AS decimal) AS ItemPriceIncVat FROM tblProducts END SELECT
  dbcomm=New OleDbCommand(sql,dbconn)
  dbread=dbcomm.ExecuteReader()
  admin.DataSource=dbread
  admin.DataBind()
  dbread.Close()
  dbconn.Close()
  end sub

The error (with or without END SELECT) is:

Select Case' must end with a matching 'End Select'.

What am I doing wrong?

And do I have to create a new value ItemPriceIncVat in the table (which would be blank)?
Once the calculation works, how do I call it from the <ItemTemplate>?
0
 
LVL 9

Accepted Solution

by:
Type25 earned 2000 total points
ID: 13495985
sub Page_Load
  dim dbconn,sql,dbcomm,dbread
  dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("admin.mdb"))
  dbconn.Open()
  sql="SELECT CAST([ItemPrice] * 17.5 AS decimal) AS ItemPriceIncVat ,* FROM tblProducts"

  dbcomm=New OleDbCommand(sql,dbconn)
  dbread=dbcomm.ExecuteReader()
  admin.DataSource=dbread
  admin.DataBind()
  dbread.Close()
  dbconn.Close()
  end sub




<%#Container.DataItem("ItemPriceIncVat")%>  

That should do it, no need to create anything extra in the DB


0
 

Author Comment

by:DanBAtkinson
ID: 13496123
Thanks.

Now this error appears:

Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

It asks me to add <%@ Page Language="C#" Debug="true" %> to the top of the page.

If I do that then it has a problem with the subs which are clearly VB
0
 
LVL 9

Expert Comment

by:Type25
ID: 13496188
I think you have something else going on there!

Paste the entire error message
0
 

Author Comment

by:DanBAtkinson
ID: 13496300
Error:


--------------------------------------------------------------------------------

Server Error in '/' Application.
--------------------------------------------------------------------------------

IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  

Stack Trace:


[OleDbException (0x80004005): IErrorInfo.GetDescription failed with E_FAIL(0x80004005).]
   Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) +900
   ASP.index_aspx.Page_Load() +180
   System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032
0
 
LVL 9

Expert Comment

by:Type25
ID: 13496603
Have you tried adding   <%@ Page Language="VB" Debug="true" %>   to the top of your page?

and have you tried adding the above to your web.config file?
0
 

Author Comment

by:DanBAtkinson
ID: 13496758
If I replace the C# with VB, then the error is:

System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).

A problem with the line: dbread=dbcomm.ExecuteReader()
0
 
LVL 9

Expert Comment

by:Type25
ID: 13496862
You actually need to declare them as their objects, i don't really do VB so i'm not much help....however i'll give it a go:


Dim dbconn As OleDbConnection =  New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("admin.mdb"))
dbconn.Open()
 
Dim sql As String =  SELECT CAST((ItemPrice) * 17.5 AS Decimal) AS ItemPriceIncVat,* As String
 
Dim Cmd As OleDbCommand =  New OleDbCommand(sql,Cnn)
Dim reader As OleDbReader
reader = Cmd.ExecuteReader()
admin.DataSource = reader
admin.DataBind()
0
 
LVL 9

Expert Comment

by:Type25
ID: 13496888
Dim Cmd As OleDbCommand =  New OleDbCommand(sql,Cnn)

should be

Dim Cmd As OleDbCommand =  New OleDbCommand(sql,dbconn)
0
 

Author Comment

by:DanBAtkinson
ID: 13498115
This has not worked I'm afraid. I've tried a hell of a lot of different combinations.

An expression was expected from:

dim sql As String =  SELECT CAST((ItemPrice) * 17.5 AS Decimal) AS ItemPriceIncVat,* As String.

I will be back tomorrow at 09:00 GMT to check the progress of this problem and try to offer assistance with my problem.

Thanks for now.
0
 
LVL 9

Expert Comment

by:Type25
ID: 13503880
sorry, try:

dim sql As String =  "SELECT CAST((ItemPrice) * 17.5 AS Decimal) AS ItemPriceIncVat,* FROM tblProducts"

0
 

Author Comment

by:DanBAtkinson
ID: 13504253
Thankyou for that. I think that problem was solved (or at least the compiler has left it alone for now!).

But now the error is:

BC30002: Type 'OleDbReader' is not defined

with this line:

dim reader As OleDbReader
0
 

Author Comment

by:DanBAtkinson
ID: 13504295
Changed that to OleDbDataReader. Seems to work.
0
 
LVL 9

Expert Comment

by:Type25
ID: 13504376
Great....

So everything is A OK then?
0
 

Author Comment

by:DanBAtkinson
ID: 13504428
No. Unfortunately. I think what I should do is close this, award you the points and open up a different question relating to the actual database working as I think that this is kind of going beyond the original question.
0
 

Author Comment

by:DanBAtkinson
ID: 13504435
Points awarded. Thankyou for your help Type25.
0
 
LVL 9

Expert Comment

by:Type25
ID: 13504523
Thanks for the points
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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