franzrivas 0 Newbie Poster
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Dim cmd As New OleDb.OleDbCommand
    If Not cnn.State = ConnectionState.Open Then
        'open connection if it is not yet open
        cnn.Open()
    End If

    cmd.Connection = cnn
    'check whether add new or update
    If Me.txtReg.Tag & "" = "" Then
        'add new 
        'add data to table
        cmd.CommandText = "INSERT INTO patient( PatRegID, PatUsername, PatPassword, PatFName, PatMName, PatLName, PatAddress, PatContact, PatBirth, PatGender) " & _
                        " VALUES(" & Me.txtReg.Text & "','" & Me.txtUsername.Text & "'," & _
                        Me.txtPassword.Text & "'," & _
                        Me.txtFirst.Text & "','" & Me.txtMiddle.Text & "'," & _
                        Me.txtLast.Text & "'," & Me.txtAddress.Text & "', '" & _
                         Me.txtContact.Text & "','" & Me.dtpBirth.Text & "','" & _
                         Me.cbGender.Text & "')"
        cmd.ExecuteNonQuery()
    Else
        'update data in table
        cmd.CommandText = "UPDATE patient " & _
                    " SET PatRegID = " & Me.txtReg.Text & _
                    ",PatUsername = '" & Me.txtUsername.Text & "'" & _
                    ", PatPassword = '" & Me.txtPassword.Text & "'" & _
                    ", PatContact = '" & Me.txtContact.Text & "'" & _
                    ", PatBirth ='" & Me.dtpBirth.Text & "'" & _
                    ", PatFName ='" & Me.txtFirst.Text & "'" & _
                    ", PatMName = '" & Me.txtMiddle.Text & "'" & _
                    ", PatLName = '" & Me.txtLast.Text & "'" & _
                    ", PatAddress = '" & Me.txtAddress.Text & "'" & _
                     ", PatGender = '" & Me.cbGender.Text & "'" & _
                    " WHERE PatRegID = '" & Me.txtReg.Tag
        cmd.ExecuteNonQuery()

    End If
    'refresh data in list
    RefreshData()
    'clear form
    Me.btnClear.PerformClick()

    'close connection
    cnn.Close()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.