Hye,
i got problem while saved the record.
here is my code.
Imports System.Data.OleDb
Imports System.Data
Imports System.Configuration
Public Class Form2
Shared STAFF As Form2
Function GetInstance()
If STAFF Is Nothing Then
STAFF = New Form2
ElseIf STAFF.IsDisposed Then
STAFF = New Form2
End If
Return STAFF
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If txtFindId.Text = "" Then
MessageBox.Show("Insert Keyword", "Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtFindId.Focus()
ElseIf RadioButton1.Checked Then
StaffDataGridView.DataSource = Me.DsKK3DB.Staff.Select("Staff_Id like '" & txtFindId.Text & "%'")
ElseIf RadioButton2.Checked Then
StaffDataGridView.DataSource = Me.DsKK3DB.Staff.Select("Staff_IC like '" & txtFindId.Text & "%'")
ElseIf RadioButton3.Checked Then
StaffDataGridView.DataSource = Me.DsKK3DB.Staff.Select("Staff_Name like '" & txtFindId.Text & "%'")
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DsKK3DB.Staff' table. You can move, or remove it, as needed.
Me.StaffTableAdapter.Fill(Me.DsKK3DB.Staff)
Me.StaffTableAdapter.Fill(Me.DsKK3DB.Staff)
RadioButton1.Checked = True
Me.StaffTableAdapter.Fill(Me.DsKK3DB.Staff)
End Sub
Private Sub selectedRowsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles selectedRowsButton.Click
Dim indexPos As Integer = StaffDataGridView.CurrentCell.RowIndex
Me.txtId.Text = Me.StaffDataGridView.Item(0, indexPos).Value.ToString
Me.txtName.Text = Me.StaffDataGridView.Item(1, indexPos).Value.ToString
Me.txtIC.Text = Me.StaffDataGridView.Item(2, indexPos).Value.ToString
Me.txtExt.Text = Me.StaffDataGridView.Item(3, indexPos).Value.ToString
Me.txtHP.Text = Me.StaffDataGridView.Item(4, indexPos).Value
Me.txtEmail.Text = Me.StaffDataGridView.Item(5, indexPos).Value.ToString
Me.txtPosition.Text = Me.StaffDataGridView.Item(6, indexPos).Value.ToString
End Sub
Private Sub BbtnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRefresh.click
StaffDataGridView.DataSource = Me.DsKK3DB.Staff
txtFindId.Text = ""
RadioButton1.Checked = True
txtId.Text = ""
txtName.Text = ""
txtIC.Text = ""
txtHP.Text = ""
txtExt.Text = ""
txtEmail.Text = ""
txtPosition.Text = ""
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Me.StaffBindingSource.AddNew()
txtId.Enabled = True
txtName.Enabled = True
txtIC.Enabled = True
txtHP.Enabled = True
txtExt.Enabled = True
txtEmail.Enabled = True
txtPosition.Enabled = True
txtId.Text = ""
txtName.Text = ""
txtIC.Text = ""
txtHP.Text = ""
txtExt.Text = ""
txtEmail.Text = ""
txtPosition.Text = ""
txtId.Focus()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.StaffBindingSource.CancelEdit()
txtId.Enabled = False
txtName.Enabled = False
txtIC.Enabled = False
txtHP.Enabled = False
txtExt.Enabled = False
txtEmail.Enabled = False
txtPosition.Enabled = False
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
txtId.Enabled = False
txtName.Enabled = True
txtIC.Enabled = True
txtEmail.Enabled = True
txtPosition.Enabled = True
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Me.Validate()
Me.StaffBindingSource.EndEdit() 'this is an error while saved the data
Me.TableAdapterManager.UpdateAll(Me.DsKK3DB)
End Sub
Private Sub StaffBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StaffBindingNavigatorSaveItem.Click
Me.Validate()
Me.StaffBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DsKK3DB)
End Sub
End Class