后台工作者和ODBC查询

时间:2015-11-18 15:58:15

标签: database vb.net odbc backgroundworker

我想将数据库提取到后台工作程序中,但是如果没有Visual Studio在我的代码中返回错误,它似乎崩溃了。

这是DoWork中的代码:

Private Sub ITSM_Fetch_BW_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles ITSM_Fetch_BW.DoWork
    Dim sql As String = "xxxx"

    Dim ConnString As String = "DRIVER={AR System ODBC Driver};ARServer=xxxx;ARServerPort=xxxx;ARPrivateRpcSocket=xxxx;UID=xxxx;PWD=xxxx;ARAuthentication=;ARUseUnderscores=1;SERVER=NotTheServer"
    Dim connection As New Odbc.OdbcConnection(ConnString)
    connection.Open()

    Dim ODBC_Command As New Odbc.OdbcCommand(sql, connection)

    Dim ODBC_reader As Odbc.OdbcDataReader

    'Load the Data into the local Memory
    ODBC_reader = ODBC_Command.ExecuteReader

    e.Result = ODBC_reader
    ODBC_reader.Close()
End Sub

Private Sub ITSM_Fetch_BW_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles ITSM_Fetch_BW.RunWorkerCompleted
    Data = New DataTable
    Data.Load(e.Result)

    Dim Count_ToDo(5) As String
    Count_ToDo(0) = "Product_Name"
    Count_ToDo(1) = "Status"
    Count_ToDo(2) = "Language"
    Count_ToDo(3) = "Assigned_Group"
    Count_ToDo(4) = "Priority"
    Count_ToDo(5) = "Company"

    For Each Item As String In Count_ToDo
        Dim i As Integer = 0
        Dim ITEM_Count(0, 1) As String

        For Each Ticket As DataRow In Data.Rows

            'PART FOR THE CI
            If IsDBNull(Ticket.Item(Item)) = False Then

                Dim IsInIndex As Integer = -1
                If i = 0 Then
                    ITEM_Count(0, 0) = Ticket.Item(Item)
                    ITEM_Count(0, 1) = 1
                Else


                    For x As Integer = 0 To ITEM_Count.GetLength(0) - 1
                        If ITEM_Count(x, 0) = Ticket.Item(Item) Then
                            IsInIndex = x
                        End If
                    Next

                    If IsInIndex = -1 Then
                        Dim ITEM_Count_Temp(ITEM_Count.GetLength(0), ITEM_Count.GetLength(0)) As String
                        ITEM_Count_Temp = ITEM_Count
                        ReDim ITEM_Count(ITEM_Count.GetLength(0), 1)
                        For x As Integer = 0 To ITEM_Count_Temp.GetLength(0) - 1
                            For y As Integer = 0 To ITEM_Count_Temp.GetLength(1) - 1
                                ITEM_Count(x, y) = ITEM_Count_Temp(x, y)
                            Next
                        Next


                        ITEM_Count(ITEM_Count.GetLength(0) - 1, 0) = Ticket.Item(Item)
                        ITEM_Count(ITEM_Count.GetLength(0) - 1, 1) = 1
                    Else
                        ITEM_Count(IsInIndex, 1) = ITEM_Count(IsInIndex, 1) + 1
                    End If
                End If
            Else
                'IF NULL
            End If


            i = i + 1
        Next

        'CI_COUNT FILLING
        'ORDERING BY COUNT
        Dim ITEM_obj = New List(Of obj)
        Dim ITEM_ToObj As String = ""
        Dim ITEMCount_ToObj As String = ""

        For x As Integer = 0 To ITEM_Count.GetLength(0) - 1
            ITEM_ToObj = ITEM_Count(x, 0)
            ITEMCount_ToObj = ITEM_Count(x, 1)
            ITEM_obj.Add(New obj(ITEM_ToObj, ITEMCount_ToObj))
        Next


        ITEM_obj = OrderItem(ITEM_obj)

        Dim Item_Count_listview As ListViewItem

        For Each Itemobj As obj In ITEM_obj
            Dim Transfer_Array(2) As String
            Transfer_Array(0) = Itemobj.Item
            Transfer_Array(1) = Itemobj.Item_Count
            Item_Count_listview = New ListViewItem(Transfer_Array)
            Select Case Item
                Case "Product_Name"
                    CI_Count_Table.Items.Add(Item_Count_listview)
                Case "Status"
                    Status_Count_Table.Items.Add(Item_Count_listview)
                Case "Language"
                    Language_Count_Table.Items.Add(Item_Count_listview)
                Case "Assigned_Group"
                    AssignedGroup_Count_Table.Items.Add(Item_Count_listview)
                Case "Priority"
                    Priority_Count_Table.Items.Add(Item_Count_listview)
                Case "Company"
                    LOB_Count_Table.Items.Add(Item_Count_listview)
                Case Else
                    MsgBox("No Category Of this type exist. Programming Issue. Item is: " & Item)
            End Select
        Next
    Next
End Sub

有什么不可能遇到像这样的后台工作者?

的问候,

0 个答案:

没有答案