Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    TextBox1.Text = ComboBox1.SelectedValue
    Me.Salary_tableTableAdapter.FillBy(Me.Emp_mngmtDataSet.Salary_table, empno:=TextBox1.Text)
End Sub


After Executing this. the program runs smoothly but when we close the program using the close window of the specific form. The Error Message pops up

"Conversion from string "" to type 'Integer' is not valid."

Please help me fix this.. Iam a novice...

Here is the full coding of the same form:

VB
Public Class Form3

    Private Sub Salary_tableBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Salary_tableBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Salary_tableBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Emp_mngmtDataSet)

    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Emp_mngmtDataSet.Emp_table' table. You can move, or remove it, as needed.
        Me.Emp_tableTableAdapter.Fill(Me.Emp_mngmtDataSet.Emp_table)
        'TODO: This line of code loads data into the 'Emp_mngmtDataSet.Salary_table' table. You can move, or remove it, as needed.
        If TextBox1.Text <> "" Then
            Me.Salary_tableTableAdapter.FillBy(Me.Emp_mngmtDataSet.Salary_table, empno:=TextBox1.Text)
        ElseIf TextBox1.Text = "" Then
            TextBox1.Text = ComboBox1.SelectedValue
        End If
        Me.Salary_tableTableAdapter.FillBy(Me.Emp_mngmtDataSet.Salary_table, empno:=TextBox1.Text)

    End Sub

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

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form6.Show()
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        TextBox1.Text = ComboBox1.SelectedValue
         Me.Salary_tableTableAdapter.FillBy(Me.Emp_mngmtDataSet.Salary_table, empno:=TextBox1.Text)
    End Sub
End Class


Please help me what i have to do exactly...
Posted
Updated 20-Oct-12 22:46pm
v3

By the looks of it, you need to validate your inputs at some point.
What it seems to be complaining about is that it tried to convert TextBox1.Text to an integer, but it is blank, so it can't work out what value it should have. This implies that either ComboBox1 has nothing selected, or that the selected value is blank.

Check that ComboBox1 has a valid selection before you set the value of TextBox1.Text, and either default it to a "sensible" value, or complain to the user that he needs to complete the form first.
 
Share this answer
 
Comments
armarzook 21-Oct-12 4:49am    
How to give a valid selection ? Or either the "sensible" value.??
OriginalGriff 21-Oct-12 5:14am    
Valid selection is normally the user's department! :laugh:
You can help by selecting a value for him if it is a drop down list, but if he can enter his own value they you need to either ask him to enter one, or default it.
To default it, check for a valid value, if if there isn't one set the TextBox.Text to a sensible value. Exactly what a "Sensible Value" will be is up to you - I have no idea if "0" is sensible or "666" in the context of your system and what you do with the number!
Just passed an if else statement when the respective form loads. and made it to have a 'Sensible' Value. Anyways thanks for your ideas guys...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900