Dynamic Buttons,SaveToolStrip, adding records
Hi all im hoping someone could give me some advice, I need help trying to understand excatly why records wont save in my database, when the dynamic save button is pressed records wont add to the database same for the toolStrip with the exeption that the toolstrip will update records so im assuming the problem is with how im trying to create a record, I have worked on this extensively for three weeks and am reaching desperation. The code looks like...
Public Function CreateEmployee(ByVal ID As Integer, ByVal NewPerson As ClassEmployee) As Boolean
Dim CreateEmployeesAdapter As New DataPlasterDataSetTableAdapters.EmployeesTableAdap ter
Dim CreateEmployeesTable As New DataPlasterDataSet.EmployeesDataTable
CreateEmployeesAdapter.Fill(CreateEmployeesTable)
Dim MyRows() As DataPlasterDataSet.EmployeesRow = CType(CreateEmployeesTable.Select("ID = " & ID.ToString), DataPlasterDataSet.EmployeesRow())
If MyRows.Length > 0 Then
With NewPerson
CreateEmployeesTable.AddEmployeesRow(.FirstName, .LastName, .Address, .Phone, .Mobile, .WeekEnding, .DaysWorked, .PayPerDay, .Wages)
CreateEmployeesAdapter.Update(CreateEmployeesTable )
CreateEmployeesAdapter.Fill(CreateEmployeesTable)
End With
End If
End Function
'to determine which button was clicked
Private Sub ButtonClickedHandler(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim btnSender As Button = CType(sender, Button)
If btnSender.Name = "btnSave" Then
If Me.ValidateChildren() = True Then
RaiseEvent ButtonClicked(1)
Else
MessageBox.Show("Please enter the first and last names")
If txtFirstName.Text = vbNullString Then
txtFirstName.Focus()
Else
txtLastName.Focus()
End If
End If
ElseIf btnSender.Name = "btnCancel" Then
RaiseEvent ButtonClicked(2)
End If
End Sub
Private Sub objEmployees_ButtonClicked(ByVal iButtonType As Integer) Handles objEmployees.ButtonClicked
'If Dynamic save button pressed then save
Select Case iButtonType
Case 1
If CreateEmployee(mID, objEmployees.ClassEmployee) Then
objEmployees = New Employees
'remove the employees control
If objEmployees IsNot Nothing Then
PnlMain.Controls.Remove(objEmployees)
objEmployees = Nothing
End If
'show list control
PnlMain.Controls.Add(objList)
'resize to fill
objList.Dock = DockStyle.Fill
Else
MessageBox.Show("Person WAS NOT added successfully")
End If
Case 2
'remove employees control
If objEmployees IsNot Nothing Then
PnlMain.Controls.Remove(objEmployees)
objEmployees = Nothing
End If
End Select
End Sub
Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
'SAVE OR UPDATE employees DEPENDING ON THE STATE OF ADDMODE T/F
If objEmployees IsNot Nothing Then
If objEmployees.AddMode = True Then
If CreateEmployee(mID + 1, objEmployees.ClassEmployee) Then
MessageBox.Show("Person WAS added successfully")
objList = New List
If objEmployees IsNot Nothing Then
PnlMain.Controls.Remove(objEmployees)
objEmployees = Nothing
End If
PnlMain.Controls.Add(objList)
objList.Dock = DockStyle.Fill
Else
MessageBox.Show("Person WAS NOT added successfully")
End If
Else
If UpdatePerson(mID, objEmployees.ClassEmployee) Then
MessageBox.Show("Person WAS updated successfully")
Else
MessageBox.Show("Person WAS NOT updated successfully")
End If
End If
End If
End sub
any pointers will be greatly appreciated, Thanks in advance
|