Problem saving data into my database  
Author Message
TheQuietShadow





PostPosted: Visual Basic Express Edition, Problem saving data into my database Top

I have been trying to save the data from the TextBoxes on my form to my database, and have written the below code without any errors, but the data is not saving to the database. Can anyone please help me find what I'm doing wrong

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'Create variables for each selection'

Dim FirstName, LastName, DOB, FDOC, LDOC, MFirstName, MLastName, MAddress, MEmail, FFirstName, FLastName, FAddress, FEmail, MHome, MWork, MCell, FHome, FWork, FCell, ChildPhoto As String

'copy information from the textboxes to the variables'

FirstName = TextBox1.Text : LastName = TextBox2.Text : DOB = DateTimePicker1.Text : FDOC = DateTimePicker2.Text : LDOC = DateTimePicker3.Text

MFirstName = TextBox4.Text : MLastName = TextBox3.Text : MAddress = TextBox7.Text : MHome = TextBox9.Text : MWork = TextBox10.Text : MCell = TextBox13.Text : MEmail = TextBox15.Text

FFirstName = TextBox6.Text : FLastName = TextBox5.Text : FAddress = TextBox8.Text : FHome = TextBox12.Text : FWork = TextBox11.Text : FCell = TextBox14.Text : FEmail = TextBox16.Text

ChildPhoto = PictureBox1.ImageLocation

'Make sure names have been entered'

If FirstName = "" Or LastName = "" Then

MessageBox.Show("Please enter a first and last name.")

Else

'Copy the information from the variables to the database'

Dim newChildRow As Child_Information_DatabaseDataSet.Child_InformationRow

newChildRow = Child_Information_DatabaseDataSet.Child_Information.NewChild_InformationRow

newChildRow.FirstName = FirstName : newChildRow.LastName = LastName : newChildRow.DOB = DOB : newChildRow.FDOC = FDOC : newChildRow.LDOC = LDOC

newChildRow.MFirstName = MFirstName : newChildRow.MLastName = MLastName : newChildRow.MAddress = MAddress : newChildRow.MHome = MHome : newChildRow.MWork = MWork : newChildRow.MCell = MCell : newChildRow.MEmail = MEmail

newChildRow.FFirstName = FFirstName : newChildRow.FLastName = FLastName : newChildRow.FAddress = FAddress : newChildRow.FHome = FHome : newChildRow.FWork = FWork : newChildRow.FCell = FCell : newChildRow.FEmail = FEmail

Child_Information_DatabaseDataSet.Child_Information.Rows.Add(newChildRow)

' Save the new row to the database

Me.Child_InformationTableAdapter.Update(Me.Child_Information_DatabaseDataSet.Child_Information)

'Display the MessageBox confirming the save name'

MessageBox.Show(FirstName + " " + LastName + " has been added to the child database.")

'Hide all User Controls and show Desktop'

CCPD.Main.MainUC1.Visible = True

CCPD.Main.DailyReport1.Visible = False

CCPD.Main.ChildInfoViewer1.Visible = False

CCPD.Main.AddChild1.Visible = False

End If

End Sub




Visual Studio Express Editions6  
 
 
DMan1





PostPosted: Visual Basic Express Edition, Problem saving data into my database Top

Have you checked the information in this thread to see if it helps:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=427451&SiteID=1



 
 
tattoo





PostPosted: Visual Basic Express Edition, Problem saving data into my database Top

Here is a subroutine that I am using to much the same thing.  Hope it helps.

Post back if you have questions

I use the Try Catch feature to catch a problem if the record can't be added.


Private Sub Add_New_PN()

Dim PN_NewRow As DataRow                
Try

PN_NewRow = PnDataset.Tables("Parts").NewRow
' Populate_NewPN(PN_NewRow)  is a subroutine that puts data from form fields into database fields.
Populate_NewPN(PN_NewRow)
PnDataset.Tables("Parts").Rows.Add(PN_NewRow)
pnadapter.Update(PnDataset, "Parts")
StatusBarPanel1.Text = "P/N " & txtNewPN.Text & " Was Added"
MsgBox("New Part Number Added", MsgBoxStyle.OKOnly)
Catch

MsgBox("Error: Part Number " & txtNewPN.Text & " was not added", MsgBoxStyle.OKOnly)
End Try
 

End Sub