Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Not writing to Database

Hi all,
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
[2710 byte] By [claudecalleja] at [2007-11-11 8:29:04]
# 1 Re: Not writing to Database
There's some declarations you need to make sure you have but try this:

dbnewrow(columnname as string) = Object to refer to

Do that for each column, compile it into a dataset, then fill the data adapter with the dataset.
Mobius at 2007-11-11 21:47:23 >
# 2 Re: Not writing to Database
such as this

newPatientRow(Name) = NameTextBox.text

be patient with me, Im a complete newbie to this. I've just started learning VB.Net since I started this project :)
claudecalleja at 2007-11-11 21:48:18 >
# 3 Re: Not writing to Database
Yes! Good, but like I said, that would have to be preceded by a declaration of your "newPatientRow" name.
Mobius at 2007-11-11 21:49:27 >
# 4 Re: Not writing to Database
hi mobius. i actually got it to work!!! didnt change any code, i just had a problem with the connection strings. wooohoo!!! thanks a lot dude anyway
claudecalleja at 2007-11-11 21:50:21 >
# 5 Re: Not writing to Database
hi mobius. i actually got it to work!!! didnt change any code, i just had a problem with the connection strings. wooohoo!!! thanks a lot dude anyway

That would definitly prevent you from writing anything to the database :)
ablaye at 2007-11-11 21:51:26 >