Hi,
I have a flatfile that contains about 7500 records that are delimited by a newline character - Chr(10). I'm reading that file into a string, parsing that string, and inserting each record into a SQL Server 2000 table. Here's my code:
This takes about 3 minutes first time I run it. Each subsequent time takes about 1 minute, 45 seconds.
In ColdFusion, this program will run in about 1 minute, 30 seconds.
Is there any way to optimize my VB code to make it run faster?
Thanks in advance,
Suzanne
I have a flatfile that contains about 7500 records that are delimited by a newline character - Chr(10). I'm reading that file into a string, parsing that string, and inserting each record into a SQL Server 2000 table. Here's my code:
Code:
Dim myFile as String = Server.MapPath("file.txt")
Dim myStreamReader as StreamReader = File.OpenText(myFile)
Dim entireFile as String = myStreamReader.ReadToEnd
Dim delimeter as String = Chr(10)
Dim contentsArray = Split(entireFile, delimeter)
Dim i as Integer
Dim uic, diary, parent, inac, title, add1, add2, add3, add4, state, zip as String
For i = 0 to UBound(contentsArray)
uic = Mid(contentsArray(i), 1, 5)
diary = Mid(contentsArray(i), 6, 2)
parent = Mid(contentsArray(i), 8, 1)
inac = Mid(contentsArray(i), 9, 1)
title = Mid(contentsArray(i), 10, 50)
add1 = Mid(contentsArray(i), 60, 30)
add2 = Mid(contentsArray(i), 90, 30)
add3 = Mid(contentsArray(i), 120, 30)
add4 = Mid(contentsArray(i), 150, 25)
state = Mid(contentsArray(i), 175, 2)
zip = Mid(contentsArray(i), 177, 10)
HERE'S WHERE I INSERT EACH RECORD USING A STORED PROCEDURE
Next
lblStatus.Text = "Finished"
myStreamReader.Close()
This takes about 3 minutes first time I run it. Each subsequent time takes about 1 minute, 45 seconds.
In ColdFusion, this program will run in about 1 minute, 30 seconds.
Is there any way to optimize my VB code to make it run faster?
Thanks in advance,
Suzanne