none
UPDATE ACCESS DATABASE & SUM VAL RRS feed

  • Question

  • HI

    I want to update a row cell in the database
    The update process must be done with the sum of the value of the textbox

    I used this code but it does not and does not collect the value of the textbox to row cell in database  during the update

    Dim com As New OleDbCommand("UPDATE TRESURTOT_TB SET TRESURETOT_CREDIT=@TRESURETOT_CREDIT WHERE  TRESURETOT_ID =2", con) 
    com.Parameters.AddWithValue("@TRESURETOT_CREDIT", +VAL(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))
    con.open
    com.ExecuteNonQuery()





    • Edited by ahmeddc Friday, December 14, 2018 4:38 PM
    Friday, December 14, 2018 4:34 PM

Answers

  • Hi,

    com.Parameters.AddWithValue("@TRESURETOT_CREDIT", +VAL(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))

    =

    com.Parameters.AddWithValue("@TRESURETOT_CREDIT", 0+VAL(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))

    According to your meaning the code should be like this:

     Dim cmd1 = New OleDbCommand("select TRESURETOT_CREDIT  from TRESURTOT_TB Where TRESURETOT_ID=2", con)
            Dim i = Convert.ToInt32(cmd1.ExecuteScalar)
            cmd = New OleDbCommand("UPDATE TRESURTOT_TB SET TRESURETOT_CREDIT=@TRESURETOT_CREDIT WHERE  TRESURETOT_ID =2", con)
            cmd.Parameters.AddWithValue("@TRESURETOT_CREDIT", i + Val(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))
    
            cmd.ExecuteNonQuery()
    

    It is best to use the code provided by Viorel_.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Tuesday, December 18, 2018 11:41 AM
    Monday, December 17, 2018 2:12 AM

All replies

  • Try the next statement:

    UPDATE TRESURTOT_TB SET TRESURETOT_CREDIT = TRESURETOT_CREDIT + @TRESURETOT_CREDIT WHERE TRESURETOT_ID = 2


    Friday, December 14, 2018 5:24 PM
  • Try the next statement:

    UPDATE TRESURTOT_TB SET TRESURETOT_CREDIT = TRESURETOT_CREDIT + @TRESURETOT_CREDIT WHERE TRESURETOT_ID = 2


    hi viorel

    if cell want update val= 100

    when text =80 

    cell after update with your code = 260   not 180  why ?


    • Edited by ahmeddc Friday, December 14, 2018 5:42 PM
    Friday, December 14, 2018 5:41 PM
  • I wondering about have +VAL


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, December 14, 2018 10:12 PM
    Moderator
  • I wondering about have +VAL


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    This is just an unsuccessful guess
    Saturday, December 15, 2018 3:59 AM
  • Hi,

    com.Parameters.AddWithValue("@TRESURETOT_CREDIT", +VAL(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))

    =

    com.Parameters.AddWithValue("@TRESURETOT_CREDIT", 0+VAL(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))

    According to your meaning the code should be like this:

     Dim cmd1 = New OleDbCommand("select TRESURETOT_CREDIT  from TRESURTOT_TB Where TRESURETOT_ID=2", con)
            Dim i = Convert.ToInt32(cmd1.ExecuteScalar)
            cmd = New OleDbCommand("UPDATE TRESURTOT_TB SET TRESURETOT_CREDIT=@TRESURETOT_CREDIT WHERE  TRESURETOT_ID =2", con)
            cmd.Parameters.AddWithValue("@TRESURETOT_CREDIT", i + Val(FPAPERACUSTUPDATE.TEXT_CREDIT.Text))
    
            cmd.ExecuteNonQuery()
    

    It is best to use the code provided by Viorel_.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Tuesday, December 18, 2018 11:41 AM
    Monday, December 17, 2018 2:12 AM