i am simple cart page where it displays the content in table form and I am trying to find a way to add up the Cost column then display the total price at the bottom. Does anyone have any suggestions how to do that? The part that is confusing me is that it the table is dynamically created via ASP.
My code can be found here: http://pastie.org/341676
Any suggestions?
First off, that is a special kind of painful (asp classic in all its glory)
What you need is another variable to hold your values, and then sum it in each loop iteration
While Not objRS.EOF
totalCost = trim(objRS.Fields("quantity"))*trim(objRS.Fields("p_price"))
absoluteTotal = absoluteTotal + totalCost
...
Wend
Response.Write absoluteTotal
That will output a sum of all the totals, although you would probably want to format it better with html and whatnot
Related
I am using FastReport with Delphi. Now, I need to display sum value of each page.
I mean, I need sum value for current page on each page of the report.
How can I achieve that? Thanks
Solution:
You can use "Page Footer" band and "Text" object with SUM() function for that purpose.
Steps to follow:
put a PageFooter band (TfrxPageFooter) on you report page
put a memo (TfrxMemoView) on that band
set [SUM(<reportdataset."NumericColumn">, MasterData1)] as text, if you want to sum records only on current page
set [SUM(<reportdataset."NumericColumn">, MasterData1, 2)] as text, if you want to sum records from current page and previous pages.
Notes:
You can use "Report Summary" band if you want to show aggregate information after all rows of your report.
ColumnFooter1
[SUM(<frxUserDataSet1."user_total_1">,MasterData1)]
I have done this a couple years ago but can't seem to remember how; I am working with access 2010 and the macro builder as opposed to VBA ( I don't do this enough for the coding).
Anyways what I have is a main form that has a subform that displays as a datasheet. This subform data source is a query that asks for three values which are applied as filters using just a where statement.
The query SQL is a select statement, followed by from and then a where statement and no parameter statement.
What I am trying to do is get the subform when it opens to pull the parameters from the main form record it is under.
I know this is possible because I have done this a couple years ago but don't have that database anymore. I have gone through all the books I have and still can't seem to find a combination that works.
Any suggestions or help with what I am missing?
****Update******
The set value isn't working... What I have is a form SQ_Ticket that has fields Site Number, Date Submitted, and End Date. I then I have a sub form that is based on a parameter query, it has a different number of fields then then the ticket query so a Union is too much of a hassle. But the fields in the sub form that would relate to the main form are Site Number and create date.
What I am trying to do is I have the main form (SQ_Ticket) with a sub form (SQ_Alarm_Parameter subform) and the form is a datasheet. When I click to expand the subdatasheet I want the Parameter query to pull the Site Number from the main form and use it to match to the site number in the subform and the pull the Date Submitted and End Date and use it as the start and end in a between statement for the create date in the sub form.
Basically I want to use find all records in the sub form (SQ_ALarm_Parameter subform) that have the same Site Number as the record in SQ_Ticket and that are Created between the Date Submitted and End Date of the Record in SQ_Ticket.
I seem to recall needing to pull the specific data from the main form and then using it as a temp value in the subform, but again can't remember how do to do that.
I know I am missing something obvious since I know I have done this before, but I didn't think to keep a copy of that work and it was quite a while ago. So I really appreciate the help
Firstly, I think taking a few minutes to do the VBA would be valuable and easier to work with. However with the macro method you can just use the Set Value submacro. This won't show up by default so you will need to select "Show All Actions" on your ribbon at the top of Access.
The Macro:
This will allow you to set the RecordSource for one form based off of value of a textbox on another form. You just need to adjust now work with your fields and parameters.
On the page I have created I have a search facility that if a doctors number is searched it will bring up the doctors details, once search button is clicked the results are displayed in textboxes (I cannot use gridviews because this is not wanted)
sample of code placed on the search button
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocNum.Text = Result1
Query statement = "SELECT DocName FROM tblDoctor WHERE DNum LIKE '%"
execute the query and get the result
The result is converted to string and Execute Scalar is used
DocName.Text = Result2
etc.... there are are 14 other textboxes that I want too display data in, so there is a large amount of repeated lines of code following the structure above. Can anyone suggest a better way of doing this?
Another problem of repetition of code comes from the prev page that is linked to it. The page before has a summary of details of doctors, once the row is clicked it takes you to this page displaying a more detailed view of their personal details. The doctor number selected will be passed onto the more detailed view using a querystring so I have the code
Automatic population of the selected doctors will fill the labels
on page load
Request the query string and store into variable dNum
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
Query statement = "SELECT DocNumber FROM tblDoctor WHERE DNum = " & dNum"
Get result from query convert to string and use execute scalar
lblDocNum.Text = Res1
etc...
What I am doing works correctly but the coding style looks poor. Any help would be much appreciated.
Thank you
Why not use a DataReader or DataSet or whatever you prefer to return the whole record, then simple move from column to column and populate the textboxes that way? Instead of returning one value at a time.
If the goal is less code,
SELECT * FROM tblDoctor WHERE xxx
into a DataTable or DataReader, as Thyamine suggested, above.
From there, you could also put the textboxes in an HTML table in a Repeater which you will bind to that datatable. You won't have to individually assign any of the values, the databinding will do it for you!
I know that people think HTML tables are evil but it's the easiest way to line up the labels I assume you will also want.
I also know that the control I suggested is called a Repeater but you only have one record. If you don't tell the compiler, I won't. :)
From parts of your question, it sounds like you're wondering whether to send all of the bits of information along in the querystring but that doesn't sound like a good idea to me because it invites users to mess with the data in the querystring.
You didn't mention - are these textboxes meant for editing? A Save button inside the Repeater would have easy access to all of the controls to build your update statement. You could also put the Save button outside the repeater and refer to the repeater's first Item to find the controls.
Here's the current situation: I have a recordset of products. The price of these products depends upon other information elsewhere on the page. So, as I loop through the recordset for output, I calculate the price using a function, and display it. This all works wonderfully.
Now, for the new wrinkle. I need to be able to sort the products by the calculated price before I display them. My attempt was to simply add a new field to the recordset, loop through the recordset once to calculate the price and update that new field, and then resort the recordset on that field before looping again for the display.
Needless to say, this does not work. No matter what settings (lockType, cursorType, cursorLocation) I put on this recordset, I am presented with an error stating "Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype."
Is there any way to make this work as described, or is there another method of accomplishing this result? For reference, here is the code snippet that I am currently working with.
set rsProd = server.CreateObject("adodb.recordset")
rsProd.cursorType = adOpenKeyset
rsProd.lockType = adLockPessimistic
rsProd.cursorLocation = adUseServer
rsProd.Open sql, Conn1
'loop through the records and calculate prices'
Do until rsProd.EOF
laPrices = Split(GetParameterProductPrice(rsProd("Product_ID")), "|")
'ERROR OCCURS ON NEXT LINE'
rsProd("Sale") = CDbl(laPrices(0))
rsProd("Sale_Special")= CDbl(laPrices(1))
rsProd.MoveNext
Loop
rsProd.MoveFirst
rsProd.Sort = "Sale_Special, Sale, Product_Code"
One way to accomplish this would be a computed column in your database.
The main benefit would be that you wouldn't need to change your page(s). Additionally you could reuse the calculated price in other places in your application - I guess you actually calculate the price again on other parts of the site.
If this recordset is not huge, one solution is during your loop, store your calculated price into an array. Once you've calculated the pricing, you can sort the array with a sorting function and then print out the results.
I want to display time starting from 8AM To 7PM With interval 15 minutes. So:
8.15AM
8.30AM
8.45AM
9AM
9.15AM
9.30AM
In a dropdownlist. Is there any built-in control in ASP.NET other than dropdownlist to display time?
You can find something at eworldui or codeproject
Doing a search for "asp.net time picker" will reveal some others, too.
There is nothing native to display time, you'll need to do it in a drop down list. From a usability perspective, I'd be inclined to break it into one list for hour and another for the 15 minute interval. Depending on your design, you may have the values for the lists stored in a database so can just bind the tables to the lists or alternatively just implement a loop within the code behind and add the list items programmatically.
To fill your dropdownlist, you could try something like:
Dim dt As DateTime = #8:00:00 AM#
For i As Integer = 0 To 44
DropDownList1.Items.Add(dt.ToString("hh:mmtt"))
dt = DateAdd(DateInterval.Minute, 15, dt)
Next