Share via

DataGridView update problem after adding and modifying

ahmedAlie 161 Reputation points
2021-01-06T10:32:41.227+00:00

Hi
I have a 2form.
1-I have a form interface that is the basic interface with DataGrid View to display data.
2-I have another interface for adding and modifying operations like Inside the input tools are Text, Label and DataTime ....
The operations are done in an excellent way, but the problem is that I want to update the datagrid on the first interface with new data after updating or modifying or insert add, but the process is not completed when it is placed with the add or modification code and is called the Add and Modify interface.
Note that if you perform the operation with a different button or sub, it will take place without problems, I mean to update the data

Sub UpdateEmployee()

    Try

        Dim com As New OleDbCommand("UPDATE   EMPLOYEE_TB SET    EMPLOYEE_NAME =@EMPLOYEE_NAME, EMPLOYEE_NATURALWORK =@EMPLOYEE_NATURALWORK, EMPLOYEE_ADDRESS =@EMPLOYEE_ADDRESS, EMPLOYEE_TELEPHON =@EMPLOYEE_TELEPHON, EMPLOYEE_SALARY =@EMPLOYEE_SALARY, EMPLOYEE_NOTE =@EMPLOYEE_NOTE, EMPLOYEE_DATE =@EMPLOYEE_DATE WHERE EMPLOYEE_CODE =@EMPLOYEE_CODE", con)
        com.Parameters.AddWithValue("@EMPLOYEE_NAME", OleDbType.VarChar).Value = EMPLOYEEUPDATE.TEXT_EMPLOYEE.Text
        com.Parameters.AddWithValue("@EMPLOYEE_NATURALWORK", OleDbType.VarChar).Value = EMPLOYEEUPDATE.COMBO_NATURAL.SelectedItem
        com.Parameters.AddWithValue("@EMPLOYEE_ADDRESS", OleDbType.VarChar).Value = EMPLOYEEUPDATE.TEXT_CLIENTADDRES.Text
        com.Parameters.AddWithValue("@EMPLOYEE_TELEPHON", OleDbType.VarChar).Value = EMPLOYEEUPDATE.TEXT_CLIENTTELEPHON.Text
        com.Parameters.AddWithValue("@EMPLOYEE_SALARY", OleDbType.Single).Value = EMPLOYEEUPDATE.TEXT_SALARY.Text
        com.Parameters.AddWithValue("@EMPLOYEE_NOTE", OleDbType.VarChar).Value = EMPLOYEEUPDATE.TEXT_CLIENTNOT.Text
        com.Parameters.AddWithValue("@EMPLOYEE_DATE", OleDbType.Date).Value = EMPLOYEEUPDATE.DATATIM_DATERECOR.Value.ToShortDateString
        com.Parameters.AddWithValue("@EMPLOYEE_CODE", OleDbType.VarChar).Value = EMPLOYEEUPDATE.LAB_CODEVAL.Text
        con.Open()
        com.ExecuteNonQuery()
        con.Close()

        'The following code. The update code with the new data does not show or is ignored.؟؟؟؟

        Dim DataAdapter As New OleDbDataAdapter("SELECT TOP 1 EMPLOYEE_ID,EMPLOYEE_CODE,EMPLOYEE_NAME,EMPLOYEE_NATURALWORK,EMPLOYEE_TELEPHON FROM  EMPLOYEE_TB WHERE EMPLOYEE_CHECK=TRUE AND  EMPLOYEE_ID =  " & EMPLOYEEUPDATE.LAB_IDVAL.Text.Trim & "   ORDER BY EMPLOYEE_NAME ASC", con)

        DTATGREG.Clear()
        DataAdapter.Fill(DTATGREG)

    Catch ex As Exception

        Exit Sub
    End Try

End Sub

Developer technologies | VB

Answer accepted by question author

Viorel 126.9K Reputation points
2021-01-06T10:39:28.26+00:00

Try “…WHERE EMPLOYEE_CHECK=1…” and insert MsgBox(ex.Message) inside the Catch block in order to not miss important error details. Show here the error message, if any.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.