none
update concerns vb.net RRS feed

  • Question

  • Update Concerns

    I have a form with 10 textboxes, when I pull values from  a table and populate some textboxes,  edit two or more of the textboxes and change the record Nok_ID to 12 from 23, It will update record ID 12, What can I do to not allow clients to edit the Nok_ID on the form? Or maybe allow some select people to edit the ID If need be?  I am working with vb.net. Below is my code

    Al

    Select Statement
      cmd = New OleDbCommand("Select * From StudentNOK WHERE NOK_ID = @StuID", conn)
            cmd.Parameters.AddWithValue("NOK_ID", txtStudentID.Text)
            dr = cmd.ExecuteReader
            If dr.Read Then
                
                txtSurname.Text = dr.Item("SurName").ToString
                txtFirstName.Text = dr.Item("FirstName").ToString
    
    The update code
    cmdText = "Update StudentNOK set SurName=?,FirstName =? Where NOK_ID=?"
                Dim cmd As New OleDb.OleDbCommand(cmdText, conn)
                cmd.Parameters.AddWithValue("?", txtSurname.Text)
                cmd.Parameters.AddWithValue("?", txtFirstName.Text)
                cmd.Parameters.AddWithValue("?", txtID.Text)
                cmd.ExecuteNonQuery()
    

    Sunday, January 21, 2018 3:23 PM

Answers

  • Hi alobi,

    >>What can I do to not allow clients to edit the Nok_ID on the form? Or maybe allow some select people to edit the ID If need be?  I am working with vb.net. Below is my code

    I would suggest that you do a judgement on people name, if who does not have permission, you could set TextBox to readonly. like this:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim user As String = "you could retrive it from databse"
            If user = "NoPermissionPerson" Then
                TextBox1.ReadOnly = True
            End If
        End Sub

    Best regards,

    Zhanglong


    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 alobi Tuesday, January 23, 2018 10:52 AM
    Monday, January 22, 2018 1:53 AM
    Moderator
  • If NOK_ID is a primary key in the table then it should not be changed/updated. Otherwise, you can use the suggestion posted by Zhanglong Wu.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by alobi Tuesday, January 23, 2018 10:52 AM
    Monday, January 22, 2018 2:13 PM

All replies

  • Hi alobi,

    >>What can I do to not allow clients to edit the Nok_ID on the form? Or maybe allow some select people to edit the ID If need be?  I am working with vb.net. Below is my code

    I would suggest that you do a judgement on people name, if who does not have permission, you could set TextBox to readonly. like this:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim user As String = "you could retrive it from databse"
            If user = "NoPermissionPerson" Then
                TextBox1.ReadOnly = True
            End If
        End Sub

    Best regards,

    Zhanglong


    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 alobi Tuesday, January 23, 2018 10:52 AM
    Monday, January 22, 2018 1:53 AM
    Moderator
  • If NOK_ID is a primary key in the table then it should not be changed/updated. Otherwise, you can use the suggestion posted by Zhanglong Wu.


    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Marked as answer by alobi Tuesday, January 23, 2018 10:52 AM
    Monday, January 22, 2018 2:13 PM