Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculation confusions

Status
Not open for further replies.

CGreenMTU

Programmer
May 27, 2004
61
US
This is probably going to be a very vague/general post, so i'm just giving you a heads up. I'm very confused about something. We have web forms set up, in which a user types in a dollar amount, which in turn is saved to a table in an Access database. We want to create some read-only textboxes, which could calculate (add or subract) what the user enters into the dollar amount. So, when the user enters a dollar amount, we'd like it to add or subract to the current amount in the database and display in the read-only textbox.

for example, say a value of $400 is in field "amount" for user ID "1" in the database. And on the form, if we put another $400, we'd like that to send to the database, and also add the value to the amount already in the database, and display it on the form in a read-only textbox. I've probably confused you by now, but i'm completely lost on this concept.

if anyone knows of any examples or anything that may help me out, please let me know! you don't know how much i would appreciate it!!!

Thanks Alot!
 
Some Clarification Please...

Ok, the field that you want to be a read only label, is this the sum of all amounts for that user?

Hope everyone is having a great day!

Thanks - Jennifer
 
Yes...that is correct...The read-only field will be the sum of all amounts for a single user.

 
Use either a Dataset or DataReader to bring back the sum from the database with a query. You will need to redo this each time the user adds another amount. Hope this helps.

If you need more tell me whether you want VB or C#

Hope everyone is having a great day!

Thanks - Jennifer
 
i'm programming in VB.NET. more help would be greatly appreciated...

thanks alot
 
Ok, so instead of making two database hits, why not:

[ol]
[li]Extract the current total from the database (populate the read-only textbox with this)[/li]
[li]Take input from the user (dollar amount)[/li]
[li]Increment the value in the read-only textbox based on the entered value (not a database hit)[/li]
[li]Store the new value in the database[/li]
[/ol]

This way, there are only two database hits being made:
- When the page loads
- When the user increments the value
- (Get the new value) << We got rid of this one

I haven't really worked with Access in .Net so forgive the lack of database code here, but it might look something like this:

Code:
public class MainPage : System.Web.UI.Page
{
    public int m_iCurrentVal = 0;

    private void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        /*
          Database code here to get current value
          We'll use this to set the m_iCurrentVal member.
        */
        this.m_iCurrentVal = Convert.ToInt32([DataView][0]["[TableColumn]");
        this.ReadOnlyTextBox.Text = this.m_iCurrentVal.ToString();
    }

    private void btn_add_click(object sender, EventArgs e)
    {
        // Do isnumeric check on the textbox value before this
        this.IncrementValue(Convert.ToInt32(ReadOnlyTextBox.Text);
    }

    private void IncrementValue(int val)
    {
        // Database code to add new value
        this.m_iCurrentVal += val;
        this.ReadOnlyTextBox.Text = this.m_iCurrentVal.ToString();
    }
}

Please forgive any syntax errors (I wrote that freehand).

Hope that's what you're looking for

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Sorry... Just saw that you're programming in vb.net (musta posted it while i was working on that :p). Converting that stuff to vb shouldn't too difficult.

Sorry - I don't have any experience with vb.net, so I can't do it :)

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
1. Extract the current total from the database (populate the read-only textbox with this)
2. Take input from the user (dollar amount)
3. Increment the value in the read-only textbox based on the entered value (not a database hit)

that is basically what I want to achieve, however, the new added or subracted amount in the read-only textbox will not be saved to the database. If i do a search for a user in the textboxes, it should display the total of all amounts entered into the database. Is this possible without having the total amount stored in the database?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top