Import System.Data.OleDb
' Insert ข้อมูล
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim cmdSave As OleDbCommand
Dim strSave As String
strSave = "Insert Into Employees (Firstname,LastName) Values ('" & txtFname.Text & "','" & txtLname.Text & "')"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\EmployeeDB.mdb;User Id=;Password=;"
conn = New OleDb.OleDbConnection(strConn)
conn.Close()
conn.Open()
Try
cmdSave = New OleDbCommand(strSave, conn)
cmdSave.ExecuteNonQuery()
cmdSave.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim delemp As String
If (TextBox1.Text = "") Then
MessageBox.Show("กรุณาเลืกข้อมูลที่จะลบก่อน", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If MessageBox.Show("คุณต้องการลบจริงๆใช่ไหม", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = MsgBoxResult.Yes Then
Try
delemp = "DELETE ID_Employee FROM Employee WHERE (ID_Employee = '" & TextBox1.Text & "')"
conn.Open()
TextBox1.Enabled = True
With cmd
.CommandType = CommandType.Text
.CommandText = delemp
.Connection = conn
.ExecuteNonQuery()
End With
Catch ex As Exception
MessageBox.Show("ลบข้อมูลไม่ได้ กรุณาตรวจสอบข้อมูลที่เลือก", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim cmddel As New OleDbCommand
Try
Finally
TextBox1.Text = " "
TextBox4.Text = " "
TextBox3.Text = " "
TextBox2.Text = " "
TextBox38.Text = " "
conn.Close()
End Try
MessageBox.Show("ลบข้อมูลเรียบร้อยแล้ว", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Employeeshow()
TextBox1.Enabled = True
Else
Me.Employeeshow()
End If
End Sub
End Class