Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:04:34+00:00 2026-06-14T18:04:34+00:00

I have a form with a tabcontrol in it with 4 tabpages each has

  • 0

I have a form with a tabcontrol in it with 4 tabpages each has it’s own texboxes and comboboxes, then I have a button outside of the tabcontrol wich builds a SQL string from all the values entered in these boxes even if some are left blank, the issue is that when i press the button i get a null reference exception and even when I use Try..Catch or on error resume next the compiler refuses to create the text string.
here is the code I have:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles btnUpdate.Click
    If Me.BankGuidTextBox.Text = vbNullString Then
        Me.BankGuidTextBox.Text = Guid.Empty.ToString
    End If
    If Me.BankNumTextBox.Text = vbNullString Then
        Me.BankNumTextBox.Text = 0
    End If
    If Me.NameTextBox.Text = vbNullString Or Me.CodeTextBox.Text = vbNullString Then
        GoTo outofsub
    End If
    Try
        Dim strSQL3 As String
        strSQL3 = "USE MSILHR" & vbCrLf & _
            "UPDATE employee SET Code = '" & Me.CodeTextBox.Text & "', Name = '" &  Me.NameTextBox.Text & "', Latinname = '" & Me.LatinNameTextBox.Text & "', Barcode = '" & Me.BarcodeTextBox.Text & "', FirstName = '" & Me.FirstNameTextBox.Text & "', LastName = '" & Me.LastNameTextBox.Text & "', idFather = '" & Me.IdFatherTextBox.Text & "', idMother = '" & Me.IdMotherTextBox.Text & "', idBirthDate = '" & Me.IdBirthDateDateTimePicker.Text & "', idBirthplace = '" & Me.IdBirthPlaceTextBox.Text & "', idSex = '" & Me.IdSexComboBox.SelectedValue & "', idMaritalstat = '" & Me.IdMaritalstatComboBox.SelectedValue & "', idSmoker = '" & Me.IdSmokerComboBox.SelectedValue & "', idMilitary = '" & Me.IdMilitaryComboBox.SelectedValue & "', idRegistry = '" & Me.IdRegistryTextBox.Text & "', idNum = '" & Me.IdNumTextBox.Text & "', idAddress = '" & Me.IdAddressTextBox.Text & "', idNationality = '" & Me.IdNationalityTextBox.Text & "', idReligion = '" & Me.IdReligionComboBox.SelectedItem & "', idTel = '" & Me.IdTelTextBox.Text & "', idMobile = '" & Me.IdMobileTextBox.Text & "', idNotes = '" & Me.IdNotesTextBox.Text & "', jStartDate = '" & Me.JStartDateDateTimePicker.Text & "', jQuitDate = '" & Me.JQuitDateDateTimePicker.Text & "', jQuitReason = '" & Me.JQuitReasonTextBox.Text & "', jSocialSec = '" & Me.JSocialSecTextBox.Text & "', jSocialdin = '" & Me.JSocialdinDateTimePicker.Text & "', jSocialdout = '" & Me.JSocialdoutDateTimePicker.Text & "', jHoliday1 = '" & Me.JHoliday1ComboBox.SelectedValue & "', jHoliday2 = '" & Me.JHoliday2ComboBox.SelectedValue & "', jEmpStat = '" & Me.JEmpStatComboBox.SelectedValue & "', jEmail = '" & Me.JEmailTextBox.Text & "', jPrevvacs = '" & Me.JPrevvacsTextBox.Text & "', jAdminvacs = '" & Me.JAdminvacsTextBox.Text & "', jHealthvacs = '" & Me.JHealthvacsTextBox.Text & "', jUnpaidvacs = '" & Me.JUnpaidvacsTextBox.Text & "', DepartmentGuid = '" & Me.DepartmentGuidComboBox.SelectedValue.ToString & "', JobTitleGuid = '" & Me.JobTitleGuidComboBox.SelectedValue.ToString & "',SalarycalctypeGuid = '" & Me.SalarycalctypeGuidComboBox.SelectedValue.ToString & "', TeamGuid = '" & Me.TeamGuidComboBox.SelectedValue.ToString & "', WorkDays = '" & Me.WorkDaysTextBox.Text & "', DaHours = '" & Me.DaHoursTextBox.Text & "', OverTimeHourPrice = '" & Me.OverTimeHourPriceTextBox.Text & "', CutSalary = '" & Me.CutSalaryTextBox.Text & "',BasicSalary = '" & Me.BasicSalaryTextBox.Text & "', SpecialSalary = '" & Me.SpecialSalaryTextBox.Text & "',CurrencyGuid = '" & Me.CurrencyGuidComboBox.SelectedValue.ToString & "', BankGuid = '" & Me.BankGuidTextBox.Text & "', BankNum = '" & Me.BankNumTextBox.Text & "', PeriodGUID = '" & Me.EmpperiodCombo.SelectedValue.ToString & "'" & vbCrLf & _
            "WHERE GUID = '" & Me.GUIDTextBox.Text & "'"

        '"update employee set Picturepath = (select name from types where type = '660')+'\" & Me.NameTextBox.Text & "' where code = '" & Me.CodeTextBox.Text & "' AND Name = '" & Me.NameTextBox.Text & "'"
        Dim dbConnection As New SqlConnection(connectionString)
        ' A SqlCommand object is used to execute the SQL commands.
        Dim cmd As New SqlCommand(strSQL3, dbConnection)

        ' Open the connection, execute the command, and close the connection.
        ' It is more efficient to ExecuteNonQuery when data is not being 
        ' returned.
        dbConnection.Open()
        cmd.ExecuteNonQuery()
        dbConnection.Close()

        MessageBox.Show("Record is updated.", _
            "Data Addition Status", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

    Catch sqlExc As SqlException
        MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    'Me.EmployeeTableAdapter.Fill(Me.MSILHRDataset.employee)

    ResetUI()
outofsub:
    MsgBox("you need to add more information!", MsgBoxStyle.Information, "Error")
End Sub

Ok new update :
I entered some data left some text boxes empty but made sure all combo boxes has values selected in them and then pressed updatebutton I got the same problem, but I redid that changed the current tab selected to any other one (from the other four) and then switched back to the previous tab, I press the button and IT WORKS!!?? it’s as if the form doesn’t Commit the values entered by user until focus changes or something it’s crazy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:04:36+00:00Added an answer on June 14, 2026 at 6:04 pm

    You are only catching a SqlException.
    You need to also catch a general exception.

    Catch sqlExc As SqlException
        MessageBox.Show(sqlExc.ToString, "SQL Exception Error!", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
    Catch exc As Exception
      MessageBox.Show(exc.ToString, "General Exception Error!", _
            MessageBoxButtons.OK, MessageBoxIcon.Error)
    

    Not sure why you are getting a null exception.
    But it is not caught because it is not a SqlException.
    On that String break it down do see where it is breaking.
    On the surface it looks like it should work.
    I suspect one of the controls is returning null rather than string.empty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

enter code here I have a TabControl on a Form and in the TabPages
I have a TabControl on my Form with two pages. Each of pages contains
I currently have a Form with a TabControl containing some TabPage s. Each TabPage
I have an application which has a tabcontrol that contains two tabpages. I have
I have a form with a tabcontrol and 4 tabs. I want to open
I have a .NET c# form with a tabcontrol on the base form. This
I have a TabControl , to which I am programmatically adding a Form with
I have a form which has only tab control in it. I want to
I have created a tab control and few forms. Each form opens in a
I have form where are 2 input fields and then i have dynamic dataTables

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.