1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
Dim cn As New OleDb.OleDbConnection
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\data.accdb"
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand
If Not Cn.State = ConnectionState.Open Then
'open connection if it is not yet open
Cn.Open()
End If
cmd.Connection = Cn
'check whether add new or update
If Me.txtdID.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = "INSERT INTO USERS(id, name, gender, password, valid) " & _
" VALUES(" & Me.txtdID.Text & ",'" & Me.txtName.Text & "','" & _
Me.cboGender.Text & "','" & Me.txtPassWord.Text & "','" & _
Me.txtValidPassWord.Text & "')"
cmd.ExecuteNonQuery()
Else
'update data in table
cmd.CommandText = "UPDATE USERS " & _
" SET id=" & Me.txtdID.Text & _
", name='" & Me.txtName.Text & "'" & _
", gender='" & Me.cboGender.Text & "'" & _
", password='" & Me.txtPassWord.Text & "'" & _
", valid='" & Me.txtValidPassWord.Text & "'" & _
" WHERE id=" & Me.txtdID.Tag
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'clear form
Me.btnClear.PerformClick()
'close connection
Cn.Close()
End Sub |
Partager