Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

I am trying to update my table Installment and table Accountabilities after having a transaction. But when I am trying to save the transaction that I did, only Payment Staus did not update and still remain. What I need to do is that if the user pays incomplete, the payment status should still be 'Not Fully Paid' otherwise if the user pay exact amount, the payment status should be 'Fully paid'. But whenever I tried to pay exactly, the payment status does not change.
here is my code:


C#
//BUTTON COMPUTE
private void button2_Click(object sender, EventArgs e)
       {
           //int lfe = 0;
           latefees.Text = "0";


           double late = Convert.ToDouble(latefees.Text);
           double txtbal = Convert.ToDouble(txt_bal.Text);
           double art = Convert.ToDouble(textBox1.Text);
           int rb = 0;

           if(art >= txtbal)
           {
               decimal tot = Convert.ToDecimal(art) - (Convert.ToDecimal(txtbal)+ Convert.ToDecimal(late));
               textBox2.Text = tot.ToString("N2");
               textBox3.Text = Convert.ToString(Math.Round(Convert.ToDecimal(rb)));

           }
           else if (txtbal > art)
           {
               decimal tot = (Convert.ToDecimal(txtbal) + Convert.ToDecimal(late)) - Convert.ToDecimal(art);
               textBox2.Text = Convert.ToString(Math.Round(Convert.ToDecimal(rb)));
               textBox3.Text = tot.ToString("N2");
           }

           if(txt_bal.Text == "0" || txt_bal.Text == "0.00")
           {
               txt_pstatus.Text = "Fully Paid";
           }


       }



// BUTTON SAVE
 private void button4_Click(object sender, EventArgs e)
        {

           

            MySqlConnection = new SqlConnection(conn.GetServers());
            MySqlConnection.Open();


            string chk = "UPDATE  tblInstallment SET Balance=@rbal,PaymentStatus=@psts,LateFees=@lfe WHERE InstallID = @ins";
            SqlCommand gc = new SqlCommand(chk, MySqlConnection);

            gc.Parameters.AddWithValue("@ins", label13.Text);
            gc.Parameters.AddWithValue("@rbal",textBox3.Text );
            gc.Parameters.AddWithValue("@psts", txt_pstatus.Text);
            gc.Parameters.AddWithValue("@lfe", latefees.Text);

            SqlDataReader rd = gc.ExecuteReader();
            rd.Close();

            string hue = "UPDATE tblAccountabilities SET Balance=@bala,PaymentStatus=@tats WHERE StudentNumber = @studnum";
            SqlCommand gc1 = new SqlCommand(hue, MySqlConnection);
            gc1.Parameters.AddWithValue("@studnum",stud_id.Text);
            gc1.Parameters.AddWithValue("@bala", textBox3.Text);
            gc1.Parameters.AddWithValue("@tats", txt_pstatus.Text);
            SqlDataReader eu = gc1.ExecuteReader();
            eu.Close();
            MessageBox.Show("Payment Information has been Updated.");

            }
Posted
Comments
George Swan 24-Jan-15 17:28pm    
I cannot see where you are updating the txt_bal.Text to reflect the new balance. If txt_bal.Text does not change the txt_pstatus.Text will not be changed.

Hi,

Could please check whether your updating all required inputs and please share me if you getting any error
 
Share this answer
 
Hi,
Change your code (both of them) as follow:

MySqlConnection = new SqlConnection(conn.GetServers());
MySqlConnection.Open();
string chk = "UPDATE tblInstallment SET Balance=@rbal,PaymentStatus=@psts,LateFees=@lfe WHERE InstallID = @ins";
SqlCommand gc = new SqlCommand(chk, MySqlConnection);
gc.Parameters.AddWithValue("@ins", label13.Text);
gc.Parameters.AddWithValue("@rbal",textBox3.Text );
gc.Parameters.AddWithValue("@psts", txt_pstatus.Text);
gc.Parameters.AddWithValue("@lfe", latefees.Text);
gc.ExecuteNonQuery();
gc.Dispose();
gc.Close();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900