Results 1 to 3 of 3

Thread: speed up code

  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have this code to save value in mdb table and use the statement addnew and update.
    Instead this 2 command if i use the sql insert i speed up the operation or not?

    Code:
    Option Explicit
    Sub UNO()
    
    	Dim objConnection As ADODB.Connection
    	Dim objRecordSet As ADODB.Recordset
    	Dim objFSO As Object
    	Dim objFile As Object
    	Dim strEmployee As String
    	Dim arrEmployee As Variant
    
    	Const adOpenStatic = 3
    	Const adLockOptimistic = 3
    	Const ForReading = 1
    	
    	Set objConnection = CreateObject("ADODB.Connection")
    	Set objRecordSet = CreateObject("ADODB.Recordset")
    	Set objFSO = CreateObject("Scripting.FileSystemObject")
    	Set objFile = objFSO.OpenTextFile("C:\EPF\CSV.txt")
    
    	objConnection.Open _
    			"Provider = Microsoft.Jet.OLEDB.4.0; " & _
    												   "Data Source = C:\APPLICAZIONI\L0928.mdb"
    
    	objRecordSet.Open "SELECT * FROM L0928", _
    					  objConnection, adOpenStatic, adLockOptimistic
    	
    	Do Until objFile.AtEndOfStream
    
    		strEmployee = objFile.ReadLine
    		arrEmployee = Split(strEmployee, "*")
    
    		objRecordSet.AddNew
    		objRecordSet("PROVA01") = arrEmployee(0)
    		objRecordSet("PROVA02") = arrEmployee(1)
    		objRecordSet("PROVA03") = arrEmployee(2)
    		objRecordSet("PROVA04") = arrEmployee(3)
    		objRecordSet("PROVA05") = arrEmployee(4)
    		objRecordSet("PROVA06") = arrEmployee(5)
    		objRecordSet("PROVA07") = arrEmployee(6)
    		objRecordSet("PROVA08") = arrEmployee(7)
    		objRecordSet("PROVA09") = arrEmployee(8)
    		objRecordSet("PROVA10") = arrEmployee(9)
    		'objRecordSet("PROVA11") = arrEmployee(10)
    		'objRecordSet("PROVA12") = arrEmployee(11)
    		objRecordSet.Update
    
    	Loop
    
    	objRecordSet.Close
    	objConnection.Close
    
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I don't think it would make a difference, since you would have to create an INSERT INTO for each line of the text file.

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='791096' date='28-Aug-2009 11:03']I don't think it would make a difference, since you would have to create an INSERT INTO for each line of the text file.[/quote]

    'm Thinking

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •