错误NullReferenceException在进度条处未处理

时间:2014-04-25 10:03:19

标签: vb.net

    Public Sub GetStationDataFromDatabase()

    Dim StationTable As New DataTable
    StationTable.TableName = "Station"


    Dim Counter As Integer
    Dim SqlString As String
    Dim OperStaRow As DataRow
    Counter = 0

    ProgressBar.Visible = True
    ProgressBar.Minimum = 1
    ProgressBar.Maximum = LocalDataSet.Tables("OR").Rows.Count
    ProgressBar.Value = 1
    ProgressBar.Step = 1
    For Each OperStaRow In LocalDataSet.Tables("OR").Rows
        SqlString = "JUST SOME STRING HERE"

        ExecuteSqlCommand(SqlString, StationTable)
        ProgressBar.PerformStep()
        ProgressBar.Refresh()
        Counter = Counter + 1

        If Counter Mod 20 = 0 Then
            Application.DoEvents()  
        End If
    Next

End Sub

所以,错误首先在progressbar.visible = True开心。即使我删除它,错误发生在它下面的行。你能告诉我什么是错的吗?

当用户选择列表框菜单时会发生这种情况。假设我有选项A和B.

1 个答案:

答案 0 :(得分:0)

我怀疑有一个输入栏对象名称的拼写错误。请检查拼写。你的代码没有任何问题。

除此之外, 我建议你查一下行数>在分配进度条最大值之前为0。

问候