need help on deposit function

Last post 05-14-2008 9:33 PM by lukelee. 10 replies.

Sort Posts:

  • need help on deposit function

    05-06-2008, 12:27 AM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

    hello, i am new on asp.net and sql, currently i am making a bank system with some basic bank services, include deposit.

    when i type in an account number and an amount and click "execute transaction", it should add the amount into the account and update the balance in the database.

    in my database, i have an Account table, Account( AccountNumber, AccountType,balance) 

    here is my execute transaction button, what codes should i write here? 

    thanks a lot 

    protected void Button3_Click(object sender, EventArgs e)
            {

                    SqlDataSource tra=new SqlDataSource();
                    tra.ConnectionString=ConfigurationManager.ConnectionStrings["shuliConnectionString"].ToString();

                    tra.InsertCommandType = SqlDataSourceCommandType.Text;
                    tra.InsertCommand = "INSERT INTO Account (balance) VALUES (@balance)";

     

  • Re: need help on deposit function

    05-06-2008, 1:49 AM

    you need to learn database programming. Search some links from google. 

    Regards.
    mimranshafiq
    .NET Web Developer
    http://www.dotnetclassic.com
  • Re: need help on deposit function

    05-07-2008, 2:34 AM
    Answer

    Based on your description,I understand you would like to update field Balance of table Account after entering AccountNumber and Amount.

    Please refer to the following suggestions:

    1.       Add two TextBox into page, named “AccountNumber” and “Amount”.
    <asp:TextBox ID="AccountNumber" runat="server"></asp:TextBox> 
    <asp:TextBox ID="Amount" runat="server"></asp:TextBox> 


    2.       Fill the button event TransactionButton_Click with the code below.  

     

    protected void TransactionButton_Click(object sender, EventArgs e)
    
    {
    
        SqlDataSource AccountDataSoure = new SqlDataSource();
    
        AccountDataSoure.ConnectionString = ConfigurationManager.ConnectionStrings["shuliConnectionString"].ToString();
    
        AccountDataSoure.UpdateCommand = "update account set balance=balance+" + Amount.Text + " where accountnumber = '" + AccountNumber.Text + "'";
    
        AccountDataSoure.Update();
    
    }
    
     

     Hope this helps.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question. This can be beneficial to other
    community members reading the thread.
  • Re: need help on deposit function

    05-07-2008, 7:45 PM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

     i got an error message, it highlights the code:

    AccountDataSource.Update();  

    and says
     

    Incorrect syntax near the keyword 'where'. 

  • Re: need help on deposit function

    05-07-2008, 7:54 PM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

    never mind, because i have set a masked edit on amount, so the amount display as 2,000,00.

    it works if i remove "," but by the way, so you know how to make it work if i just leave "," there? 

  • Re: need help on deposit function

    05-08-2008, 2:19 AM
    Answer

    It seems that you have a MarkedTextBox control in input Amount.

    I suggest that we replace Amount.Text with Convert.ToDecimal(Amount.Text).ToString().

    Hope this helps.

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question. This can be beneficial to other
    community members reading the thread.
  • Re: need help on deposit function

    05-11-2008, 11:34 PM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

    yeah, it works, thanks.

    by the way, what if i want to save the transaction record into transaction history table?

    the table is like: Transaction{transactionID* transactionType, Amount, Comments}

    and it is currently empty.

    do i use

    updateCommand or insertcommand?

     

    i tryed both,  there is no error message, but the database just doesnt update.

  • Re: need help on deposit function

    05-11-2008, 11:55 PM

    Hi,

    Cause it's a table for history, use the InsertCommand to insert a new history record.

    For example,

    AccountDataSoure.InsertCommand = "insert into Transaction(transactionID) values ('1111111')";
    int inertRowNum = AccountDataSoure.Insert();

     
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question. This can be beneficial to other
    community members reading the thread.
  • Re: need help on deposit function

    05-12-2008, 10:52 PM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

    what is int inertRowNum ? insertRowNum? i tryed both, but all syntax error.

    this is my code:

                 else if (DropDownList3.SelectedItem.Text == "transaction")
                {
                    SqlDataSource tra = new SqlDataSource();
                    tra.ConnectionString = ConfigurationManager.ConnectionStrings["shuliConnectionString"].ToString();
                    tra.UpdateCommand = "update account set balance=balance" + Convert.ToDecimal(TextBox5.Text) + "where AccountNumber = '" + TextBox4.Text + "'";
                    tra.UpdateCommand = "update account set balance=balance-" + Convert.ToDecimal(TextBox5.Text) + "where AccountNumber = '" + TextBox3.Text + "'";
                    tra.Update();
                    tra.InsertCommand = "insert into Transaction(TransactionType) values ('transaction')";
                    tra.InsertCommand = "insert into Transaction(TransactionID) values ('1')";
                    tra.Insert();
                    Server.Transfer("deposit_withdraw_confirm.aspx");
                }

  • Re: need help on deposit function

    05-13-2008, 2:04 AM
    Answer

    The variable inertRowNum is a value that represents the number of rows inserted into the underlying database.
    By the way, you may obtain some tutorials referring to the following links.
    They would be more efficient and comprehensive.

    http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/default.aspx
    http://www.asp.net/learn/data-access/?lang=cs

    Hope it helps.

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question. This can be beneficial to other
    community members reading the thread.
  • Re: need help on deposit function

    05-14-2008, 9:33 PM
    • Loading...
    • lukelee
    • Joined on 04-02-2008, 8:22 AM
    • Posts 11

    yeah, it helps, i have solve the problem, thanks again.
Page 1 of 1 (11 items)