none
Collect values while updating database RRS feed

  • Question

  • I have code to update the access dataBASE and work well
    The problem I have is when I want to update a particular cell I add a value to the cell value of the TextBox during the update directly

    For example cell with database value 100 and ,+ add value mechanism before update 50
      After the update, the value must become within 150 cell


    IUse the following code but make the cell the same value

      Sub updat_()
            'I ADD ( + ) BEFORE TEXT BUT NOT WORK 
            PURCH_.con.Open()
            Dim Sav As New OleDb.OleDbCommand
            Sav.Connection = PURCH_.con
            Sav.CommandType = CommandType.Text
            Sav.CommandText = "UPDATE TBPURCH_ SET  TBPURCH_.NUM_TBPURCH += '" & _
           NUMTYPE_.Text & "' , TBPURCH_.TOTA_TBPURCH += '" & _
             TOTAPURCH_.Text & "' where ID_TBPURCH LIKE '" & _
            IDTEXT_.Text & "'"
            Sav.ExecuteNonQuery()
            Dim DataAdapter As New OleDbDataAdapter("SELECT * FROM TBPURCH_ Order By ID_TBPURCH", con)
            If PURCH_.con.State = ConnectionState.Open Then
                PURCH_.con.Close()
            End If
        End Sub

    Wednesday, March 28, 2018 2:53 PM

All replies

  • The first thing to do is try out what you want inside of ms-access, does it work?

    If yes then build a query using parameters rather than string concatenation, if no my guess is += is invalid so you need to get the value, add to the value, update.


    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

    Wednesday, March 28, 2018 3:25 PM
    Moderator
  • I see this often in these .Net forums. People start to make a program with copy and paste but don't know what they are doing. You do it with SQL. I try to keep it simple as possible to explain some things to you. 

    With .Net there are many ways to use a database. One of the first where the DataAdapter and Crud. Crud is not S..t. But means Create Read Update and Delete. In other words you do all the commands using an OleDBCommand. 

    If you use a dataadapter, then you use in fact a tool which has that build in. You also use the Create, Read, Update and Delete (Insert, Read, Update and Delete are the SQL commands). 

    The DataAdapter needs all the commands and you cannot do it without that. That is really not easy. Because the adapter does not one row but a complete resultset. 

    Therefore there is created a commandbuilder for the DataAdapter, be aware it is a dynamic builder. It does not make code when you instance it. But it is all the time active in the DataAdapter. 

    Here an example around that for OleDB on our website

    http://www.vb-tips.com/CommandBuilderDataGridview.ASPX


    Success
    Cor


    Wednesday, March 28, 2018 6:47 PM