Not writing to Database
I have constructed a form that takes a New Patient's details, and inserts them into a table Patient.
Everything works, accept the fact that the database is not updated with the new details. As you may notice, I have built in checks along the way to make sure that the data is correct and that it is actually sent to the database. Everything checks in, apart from the fact that no new update is happening on the database.
Could you please help?
Private Sub PatientBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PatientBindingNavigatorSaveItem.Click
Me.Validate()
PatientBindingSource.EndEdit()
Dim Phone, Mobile, Nok_Phone, Nok_Mobile As Integer
Dim Name, Surname, Address, Post_Box, Email, Blood_Type, Patient_Type, Next_of_Kin_Relationship, Nok_Name, Nok_Surname As String
Dim Registration_Date, Date_of_Birth As Date
Try
Dim rowsAffected As Integer = 0
Registration_Date = DateTime.Now
Name = NameTextBox.Text
Surname = SurnameTextBox.Text
Address = AddressTextBox.Text
Post_Box = Post_BoxTextBox.Text
Email = EmailTextBox.Text
Blood_Type = Blood_TypeTextBox.Text
Patient_Type = Patient_TypeTextBox.Text
Date_of_Birth = Date_of_BirthTextBox.Text
Next_of_Kin_Relationship = Next_of_Kin_RelationshipTextBox.Text
Nok_Name = Nok_NameTextBox.Text
Nok_Surname = Nok_SurnameTextBox.Text
Try
rowsAffected = PatientTableAdapter.Insert(Registration_Date, Name, Surname, Address, Post_Box, Phone, Mobile, Email, Date_of_Birth, Blood_Type, Patient_Type, Next_of_Kin_Relationship, Nok_Name, Nok_Surname, Nok_Phone, Nok_Mobile)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'MessageBox.Show(Name)
'MessageBox.Show(Surname)
'MessageBox.Show(Date_of_Birth)
If rowsAffected > 0 Then
MessageBox.Show(CType(rowsAffected, String) + " row updated")
Else
MessageBox.Show("Could not save to Database")
End If
Catch ex As Exception
MessageBox.Show("**** Up")
MessageBox.Show(ex.Message)
Exit Sub
End Try
DatabaseDataSet.AcceptChanges()
End Sub
Many thanks,
claude

