listview中的数据插入临时表,有什么方法可以把速度提高
Sub add_temp()
 Dim rscol As New ADODB.Recordset
 If rscol.State <> 1 Then
    rscol.Open "SELECT * From tempdb.dbo.syscolumns WHERE (id = OBJECT_ID('tempdb..#temp'))", conn, 1, 1
 Else
    rscol.Requery
 End If
 
If Trim(labxin.Label1.caption) <> Biao_Ming Or Trim(labxin.Label8.caption) = "按列名查询" Then
   For i = 1 To (rscol.RecordCount - 7)
      conn.Execute "ALTER TABLE #temp DROP COLUMN col" & i + 7
   Next i
End Ifrscol.Requery
If rscol.RecordCount < 8 Then
   For m = 1 To (labxin.ListView1.ColumnHeaders.Count - 7)
    For i = 1 To labxin.ListView1.ListItems.Count - 1
     If Trim(labxin.ListView1.ListItems(i).SubItems(m + 6)) <> "" Then Exit For
     Next i
     
       If IsNumeric(labxin.ListView1.ListItems(i).SubItems(m + 6)) = True Then
        conn.Execute "alter table #temp add col" & m + 7 & " decimal(9,3)"
       Else
        conn.Execute "alter table #temp add col" & m + 7 & " varchar(200)"
       End If
       
      'Wend
     'Next i
    Next m
End If  conn.Execute "delete from #temp"
  For i = 1 To labxin.ListView1.ListItems.Count
      conn.Execute "insert into #temp(col1,col2)values('" & Trim(labxin.ListView1.ListItems(i).Text) & "','" & Trim(labxin.ListView1.ListItems(i).SubItems(1)) & "')"
        For j = 3 To labxin.ListView1.ColumnHeaders.Count
          'If IsNumeric(labxin.ListView1.ListItems(i).SubItems(j - 1)) = False Then
             'conn.Execute "ALTER TABLE #temp ALTER COLUMN col" & j & " varchar(200)"
          'End If
          conn.Execute "update #temp set col" & j & "=" & KONGTONULL(labxin.ListView1.ListItems(i).SubItems(j - 1)) & " where col2='" & Trim(labxin.ListView1.ListItems(i).SubItems(1)) & "'"
        Next j
    Next i
rscol.Close
End Sub

解决方案 »

  1.   

    插入的数据,数据类型是根据各列的数据来分析,所以数据类型是不可以马上建表来定义数据类型,而且生成的listview中的列是动态生成的,实在想不到什么方法提高插入速度,希望各位高手帮帮忙
      

  2.   

    Public Function KONGTONULL(OBJ)
    Dim OBJ1 As String
       'For Each OBJ In TextBox
          If Trim(OBJ) = "" Or IsNull(OBJ) = True Then
           KONGTONULL = "null"
          ElseIf IsNumeric(OBJ) = True Then
           KONGTONULL = "'" & Val(OBJ) & "'"
          Else
           KONGTONULL = "'" & Trim(OBJ) & "'"
          End If
       'Next
       
    End Function
      

  3.   

    select * into #temp from tableName
      

  4.   


    INSERT INTO #Temp
    SELECT
    *
    FROM
    TableName