adding records help

Joined
Jan 27, 2005
Messages
9
Programming Experience
1-3
hi would you guys help me? i made a code so that whenever i filled up all the required fields in my form a message box will tell that it has added the record. i think my code here is right but when i already filled all the information up, it displays my error handler message that
"You have missed a field. Please Go back". Although i have filled all the required field, it still comes up with the error handler. how will i possible add the record here? what's wrong with my code? what code will i replace or add if i must do so? please help..


VB.NET:
 [size=2]
[/size][size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] AddRecord()
 
[/size][size=2][color=#0000ff]Try
 
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] daSoloParent [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] OleDbDataAdapter(cmmInsert)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] dsSoloParent [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] DataSet
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] m_baptized [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] chkBaptized.Checked = [/size][size=2][color=#0000ff]True[/color][/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]m_baptized = "Yes"
 
[/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2]m_baptized = "No"
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2]cmmInsert.Connection = conConnection
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE SOLO PARENT
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParent (LastName,FirstName,MiddleName) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtLastName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtFirstName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtMiddleName.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
[/size][size=2][color=#008000] 
[/color][/size][size=2][color=#008000] 
[/color][/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE SOLO PARENT
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentInformation (HomeAddress,OfficeName,OfficeAddress,LandlineNumber,MobileNumber,BirthDate,PlaceOfBirth,Baptized,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtHomeAddress.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtOfficeName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtOfficeAddress.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSoloParentLandLineNumber.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSoloParentMobileNumber.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtBirthDate.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtPlaceOfBirth.Text & "','" & m_baptized & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSoloParentAge.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSoloParentGender.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName1.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName1.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName1.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge1.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender1.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'ADD CHILDREN MORETHAN 1
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] txtChildName2.Text <> " " [/size][size=2][color=#0000ff]Then
[/color][/size][size=2][color=#008000]
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender2.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#0000ff]ElseIf[/color][/size][size=2] txtChildName3.Text <> " " [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender2.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender3.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#0000ff]ElseIf[/color][/size][size=2] txtChildName4.Text <> " " [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge2.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender2.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge3.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender3.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO SoloParentChildren (LastName,FirstName,MiddleName,Age,Gender) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildLastName4.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildFirstName4.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildMiddleName4.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtChildAge4.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].cboChildGender4.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#008000]'ADD MODE OF PAYMENT, AMOUNT, ORNumber, and PRNumber[/color][/size]
[size=2][color=#008000]'IF THE RADIO BUTTON IS CHECKED
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] rbtnCash.Checked = [/size][size=2][color=#0000ff]True[/color][/size][size=2][color=#0000ff]Then 
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO Payment (ModeOfPayment,ORNumber,PRNumber,Amount) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtCash.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtORNo.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtPRNo.Text & "','" & m_Amount & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO Payment (ModeOfPayment,ORNumber,PRNumber,Amount) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtCheck.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtORNo.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtPRNo.Text & "','" & m_Amount & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2][color=#008000]'ADD SPONSOR
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2][color=#008000]'ADD THE CHILDREN
 
[/color][/size][size=2]cmmInsert.CommandText = "INSERT INTO Sponsor (LastName,FirstName,MiddleName,Address,LandlineNumber,MobileNumber) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorLastName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorFirstName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorMiddleName.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorAddress.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorLandlineNumber.Text & "','" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtSponsorMobileNumber.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
[/size][size=2]
 
[/size][size=2][color=#008000]'ADD RESERVATION
 
[/color][/size][size=2][color=#008000]'OPEN CONNECTION
 
[/color][/size][size=2]conConnection.Open()
 
[/size][size=2]cmmInsert.CommandText = "INSERT INTO Reservation (ReservationDate) VALUES ('" & [/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtReservationDate.Text & "')"
 
daSoloParent.Fill(dsSoloParent)
 
[/size][size=2][color=#008000]'CLOSE CONNECTION
 
[/color][/size][size=2]conConnection.Close()
 
MsgBox("You have added a record", MsgBoxStyle.Information, "")
 
[/size][size=2][color=#0000ff]Catch[/color][/size][size=2] ex3 [/size][size=2][color=#0000ff]As[/color][/size][size=2] Exception
 
[/size][size=2]MsgBox("You have missed a field. Please Go back", MsgBoxStyle.Critical + MsgBoxStyle.Information, "Error")
 
[/size][size=2][color=#008000]
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Try
 
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
[/color][/size]
 
Last edited:

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
You have hard-coded the Error message "You have missed a field. Please Go back" into the try/Catch block. Any error will now give you that message.
Try changing the MsgBox line to:
MessageBox.Show(ex3.Message, "Error")
That will give you the real error message.

Also, there is no need to keep opening and closing the connection. Open it once, do all your data transfers, then close it.

Good luck :).
 
Joined
Jan 27, 2005
Messages
9
Programming Experience
1-3
hi thanks for that.. well it clearly states: OVERFLOW
but what will i do with that? so i could really add a record?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Add a break to your code then step through each line and see where the error occurs.

Is that all there is to the error message?
 
Joined
Jan 27, 2005
Messages
9
Programming Experience
1-3
yeah it just says overflow
well, forgive me for asking too much umm.. what do you mean by adding a break to my code?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
If you have the default settings in Visual Studio, you can just click in the control colored gutter to the left of the code. That should create a breakpoint with a red dot and the background of the line of code will turn red as well. (if you don't have the gutter, you can click the Debug menu then 'New BreakPoint', or Ctrl+B, and set the breakpoint manually) When you debug, the program will stop when it reaches the breakpoint. You can then use the 'Step Into' button on the debug menu (you may have to show that menu) or use F11 to execute each line.
 
Top Bottom