Getting data from Textbox's withing a Tabcontrol

Jefferson

Member
Joined
Aug 16, 2005
Messages
21
Programming Experience
Beginner
Hi,

I am a little new to VB.net, and am having some problems, If someone would be gracious enough to help out, i would truely appreciate it.

I have a TabControl with three tabs on it, each tab contains about 10 Textbox's that capture data from the User.
The idea is to get the data from the Textbox and write it into a database but this does not seem to work.

Please see the attached Code.

Private Sub AddRecord()
Try
Dim drw1 As DataRow = DsHPayroll1.Tables("HPayroll").NewRow

drw1("ID") = txtID.Text
drw1("Account") = txtAccount.Text
drw1("AutoID") = Integer.MaxValue
DsHPayroll1.Tables("HPayroll").Rows.Add(drw1)
Catch eAddRecords As Exception
MsgBox("Action Failed, Please try again")
End Try
End Sub

Please let me know if theres any way you can guide me.

Thanks
Jefferson
 
I don't see anything wrong with what you have there. Are you getting an error? Are you sure this code is being called? Have you checked the table to make sure the row is not being added?
 
Tabcontrol & Textbox's

Hi,

When i run the debug, the mintue the code reaches the {drw1("ID") = txtID.Text} line, then the application throws an error.
Mind you, the Code for this is on frmMain and declared as a Private Sub.
The Textbox's are under the TabControl1 - Tabpage1, Tabpage2 and Tabpage3 on the frmMain screen.
 
TabControl

No error message,
Just skips past the rest of the code and hits my Catch eError.
How do i read textbox's off of a tabcontrol.Tabpage???
I think this is my main problem.
 
If it skips past your code to your Catch statement, then you must be getting an error. if it is stopping at the line

drw1("ID") = txtID.Text

then I'm betting your ID column is probably a numerical column and cannot accept string data. Try this:

drw1("ID") = Int64.Parse(txtID.Text)
 
TabControl

Hi,

This is what i though as well, but ran a little check on it after your post, unfortunatley this did not help.
I did create another 4 textbox's on the main form, and they wrote perfectley to the database, but when selecting them off the tabcontrol (or at least trying to) they crash.
I have attached the Sub "AddRecords", if you need any further information, i can zip the project and email it to you?
Once again, thank you for the help!!!

Text in red is yours
Text in green is commented out

Private Sub AddRecords()
' Create the mappings from the Application Fields to the Database.
' Consists of DropDown Combo's, Currency, Date, Numeric and Memo Fields.
Try
Dim Tabpage1 As New TabPage
Dim Tabpage2 As New TabPage
Dim Tabpage3 As New TabPage
Dim varID As New Integer
Dim VarAccount As String
Dim drw1 As DataRow = DsHollardPayroll1.Tables("HollardPayroll").NewRow
' Numeric Fields
' Me.TabControl1.Container.Add(txtAccount.Text = drw1("Account"))
' Me.TabControl1.Container.Add(txtID.Text = drw1("ID"))
' drw1("ID") = txtID.Text
' If txtID.Text = "" Then
' MsgBox("Please enter the Correct ID Number", MsgBoxStyle.OKOnly)
' Exit Try
' End If
' Count for TabPage1 - Employee Details
'TabControl1.varID = txtID.Text
'drw1("ID") = TabControl1.TabPages.IndexOf(Tabpage1) = txtID.Text
'drw1("EmployeeNumber") = TabControl1.TabPages.IndexOf(Tabpage1) = txtEmpNum.Text
'drw1("LeavePerYear") = TabControl1.TabPages.IndexOf(Tabpage1) =txtLeavePerYear.Text
'drw1("CostCode") = TabControl1.TabPages.IndexOf(Tabpage1) = txtCostCode.Text
'drw1("PostalCode") = TabControl1.TabPages.IndexOf(Tabpage1) = txtPostalCode.Text
'drw1("ResAddress") = TabControl1.TabPages.IndexOf(Tabpage1) = txtAddress.Text
'drw1("PostalAddress") = TabControl1.TabPages.IndexOf(Tabpage1) = txtPostalAddress.Text
'drw1("Email") = TabControl1.TabPages.IndexOf(Tabpage1) = txtEmail.Text
'drw1("SuperEmail") = TabControl1.TabPages.IndexOf(Tabpage1) = txtSupervisorEmail.Text
'drw1("Firstname") = TabControl1.TabPages.IndexOf(Tabpage1) = txtFirstName.Text
'drw1("CostCode") = TabControl1.TabPages.IndexOf(Tabpage1) = txtCostCode.Text
'drw1("id").TabControl1.TabPages.IndexOf(Tabpage1) = txtID.Text
'If TabControl1.TabIndex = "Tabpage1" Then
'MsgBox("1")
'drw1("id") = txtID.Text
'ElseIf TabControl1.TabIndex = "tabcontrol2" Then
' MsgBox("2")
'End If

drw1("ID") = Int64.Parse(txtID.Text)
drw1("employeenumber") = Int64.Parse(txtEmpNum.Text)
drw1("LeavePerYear") = Int64.Parse(txtLeavePerYear.Text)
drw1("ID") = txtID.Text
drw1("EmployeeNumber") = txtEmpNum.Text
drw1("LeavePerYear") = txtLeavePerYear.Text
drw1("CostCode") = txtCostCode.Text
drw1("PostalCode") = txtPostalCode.Text
drw1("ResAddress") = txtAddress.Text
drw1("PostalAddress") = txtPostalAddress.Text
drw1("Email") = txtEmail.Text
drw1("SuperEmail") = txtSupervisorEmail.Text
drw1("FirstName") = txtFirstName.Text
drw1("Surname") = txtSurname.Text
drw1("KnownAs") = txtKnownAs.Text
drw1("Initials") = txtInitials.Text
drw1("Paypoint") = txtPaypoint.Text
drw1("Manager") = txtManager.Text
drw1("JobTitle") = txtJobTitle.Text
drw1("TravelAllowance") = txtTravel.Text
drw1("HourlyTCC") = txtHourlyTCC.Text
drw1("MonthlyTCC") = txtMonthlyTCC.Text
drw1("PackageCar") = txtPackageCar.Text
drw1("BirthDate") = DateBDate.Text
drw1("GroupStartDate") = DateGStartDate.Text
drw1("GroupEndDate") = DateGEndDate.Text
drw1("cboEmployeeStatus") = cboBoxEmploymentStatus.Text
drw1("cboGender") = cboBoxGender.Text
drw1("cboGroup") = cboBoxGroup.Text
drw1("cboMaritalStatus") = cboBoxMaritalStatus.Text
drw1("cboTitle") = cboBoxTitle.Text
'
' Count for TabPage2 - Employee Details
'

drw1("LibertyMedSpouse") = txtLibertyMedSpouse.Text
drw1("LibertyMed") = txtLibertyMed.Text
drw1("Relationship") = txtRelationship.Text
drw1("KinName") = txtKinName.Text
drw1("KinSurname") = txtKinSurname.Text
drw1("cboFundSelect") = cboBoxFundSelect.Text
drw1("MedicalCondition") = txtMedicalConditions.Text
'
' Count for TabPage3 - Employee Details
'

drw1("Account") = txtAccount.Text
drw1("BranchCode") = txtBranchCode.Text
drw1("TAXNumber") = txtTaxNumber.Text
drw1("BankName") = txtBankName.Text
drw1("BranchName") = txtBranchName.Text
drw1("TaxOffice") = txtTaxOffice.Text
drw1("cboTaxStatus") = cboBoxTaxStatus.Text
'Auto Increment
drw1("AutoID") = Integer.MaxValue
DsHollardPayroll1.Tables("HollardPayroll").Rows.Add(drw1)
AddHandler OleDbDataAdapter1.RowUpdated, _
New OleDb.OleDbRowUpdatedEventHandler(AddressOf OnRowUpdated)
OleDbDataAdapter1.Update(DsHollardPayroll1, "HollardPayroll")
MsgBox("Updated", MsgBoxStyle.OKOnly)
Catch eAddRecords As Exception
MsgBox("Action Failed, Please try again")
End Try
End Sub
 
TabControl - Resolved

Hi,

I removed the Try statement for error catching, and then changed the line of code "drw1("ID") = int64.parse(txtID.text)" to rather read "drw1("ID") = Long.parse(txtID.text)" and all seems to work well from here.

This is the perfect example of a communication error (A lack of communication between My Chair and My Keyboard)...

Thanks for all the help, It is much appreciated.
 
Back
Top