如何将数据更新到数据库? [英] How to update data to the database?

查看:150
本文介绍了如何将数据更新到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在进行交易后更新我的表分期付款和表格帐户。但是当我试图保存我所做的交易时,只有支付Staus没有更新仍然保留。我需要做的是,如果用户支付不完整,付款状态仍应为未完全支付,否则如果用户支付确切金额,则支付状态应为全额支付。但每当我试图准确支付时,付款状态不会改变。

这是我的代码:





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:


//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.");

            }

推荐答案





请检查您是否更新了所有必需的输入,如果您收到任何错误请与我分享
Hi,

Could please check whether your updating all required inputs and please share me if you getting any error


您好,

更改您的代码(两者)如下:



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();
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();


这篇关于如何将数据更新到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆