dataAdapter.Fill非常慢

时间:2016-11-02 14:28:13

标签: database vb.net fill dataadapter

当我运行此代码时,它在dataAdapter.Fill(db)上变得非常慢,我不知道为什么,它可能需要90秒。

任何人都知道什么可能导致它如此缓慢?

这里有一些项目代码:

Select Case frmLoggIn.txtLoggInProdGrupp.Text
    Case "4"
        SˆkDatum = WeekSettings(Date.Today.ToString, 2)
        sSql = "SELECT MP64001 AS TO_nr, MP64002 AS Art_nr, CASE WHEN LEN(KOMMENTAR) > 0 THEN '##' + SC01002 ELSE SC01002 END AS Art_ben, MP64004 AS P_Ant, MP67040 AS R_Ant, MP67032 AS Plan_Start, MP64001 AS Start, MP67033 AS Plan_Klar, MP64001 AS Klar, MP64013 AS Lev_Datum, MP64001 AS Lev, CASE MP67058 WHEN '0' THEN 'Skapad' WHEN '1' THEN 'Ej startad' WHEN '3' THEN 'Startad' WHEN '4' THEN 'Avbruten' WHEN '5' THEN 'Avslutad' END AS Status , MP64001 AS SlaskPlat, CASE WHEN LEN(MP67068) = 0 THEN PERSON ELSE MP67068 END AS Pers, LTRIM(RTRIM(MP64017)) + ' ' + LTRIM(RTRIM(MP64018)) + ' ' + LTRIM(RTRIM(MP64019)) AS Kommentar, MP64088 AS TO_Status, MP64034 AS TO_Prio, MP67010*MP64004 AS P_Tid, COMPOK AS IOK, MP67035 AS R_Time, MP67003 AS OP_Number " & _
        "FROM WOTransComments0000 RIGHT JOIN (SC01" & CompanyNumber & "00 INNER JOIN (MP64" & CompanyNumber & "00 INNER JOIN MP67" & CompanyNumber & "00 ON MP64001 = MP67001) ON SC01001 = MP64002) ON OP = MP67006 AND WO = MP67001 " & _
        "WHERE (((MP67033)<='" & SˆkDatum & "') AND ((MP67058)<5) AND ((MP67006)='" & frmLoggIn.txtLoggInProdGrupp.Text & "'))" & _
        "ORDER BY MP67032, MP64001" 

End Select

GridShowOrders.DataSource = OpenDataTable(sSql) 'H‰mtar data 

Call GridSettings() 'Sub-rutin fˆr formatering av DataGridView


Module Module1

Friend connstr As String = "Provider=MSDASQL;DSN=MarcoscalaDB;UID=marcoscala;PWD=scala"


Friend Function OpenDataTable(ByVal sqlstr As String)
        Try
            'SearchOK = True
            Cursor.Current = Cursors.WaitCursor
            Dim db As New DataTable()
            Dim dataAdapter As New Odbc.OdbcDataAdapter(sqlstr, connstr)
            dataAdapter.ToString()
            dataAdapter.Fill(db)
            dataAdapter.Dispose()
            Cursor.Current = Cursors.Default
            Return db
        Catch e As Exception
            Cursor.Current = Cursors.Default
            If InStr(e.Message, "42S02", CompareMethod.Text) > 0 Then
                MsgBox(e.Message)
                'SearchOK = False
                Return ""
                Exit Function
            End If
            Cursor.Current = Cursors.Default
            MsgBox(e.Message)
            'SearchOK = False
            Return ""
        End Try
    End Function

End Module

0 个答案:

没有答案