错误“从字符串"转换的解决方案.键入“整数"无效."关闭表格时 [英] Solution for Error "Conversion from string "" to type 'Integer' is not valid." When Closing a form

查看:102
本文介绍了错误“从字符串"转换的解决方案.键入“整数"无效."关闭表格时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



执行完之后.程序运行平稳,但是当我们使用特定窗体的关闭窗口关闭程序时.错误消息弹出

从字符串"到类型"Integer"的转换无效."

请帮我解决这个问题..我是新手...

这是相同形式的完整编码:



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:

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...

推荐答案

从外观上,您需要在某些时候验证您的输入.
似乎在抱怨的是它试图将TextBox1.Text转换为整数,但是它为空,因此无法计算出应具有的值.这意味着要么ComboBox1没有选择任何内容,要么选择的值为空白.

在设置TextBox1.Text的值之前,请检查ComboBox1是否具有有效的选择,并将其默认设置为明智的"值,或者向用户抱怨他需要首先完成表单.
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.


在加载相应表单时仅传递了if else语句.并使其具有合理的"价值.无论如何,谢谢您的创意……
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...


这篇关于错误“从字符串"转换的解决方案.键入“整数"无效."关闭表格时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆