0

I have to import products from a denormalized table to Access 97 file. This scheme can't change, so I can't use SQL. I use the following routine to import the products. There are over 7000 products in the file and the function takes a long time. Is there any way to speed it up?

Public Sub ImportToOrders()
    Try

        'Dim actualFileName As String = IO.Path.GetFileName(filename)
        'Dim streamReader As New IO.StreamReader(filename)
        'Dim streamWriter As New IO.StreamWriter(filename & ".tsv")


        'streamWriter.WriteLine()

        'streamWriter.Close()
        'streamWriter.Dispose()

        Dim strFile As String = "C:\windows\figure.ini"
        Dim strRet As String
        Dim inifile As New IniFileManager

        strRet = inifile.ReadINI(strFile, "DATABASE SECTION", "FILENAME", "")
        Dim strPriCatFile As String = ""
        strPriCatFile = "C:\three_software\incoming\skechers\Pricat.edi.tsv"

        Dim fields As String()
        Dim counter As Integer = 0
        Dim delimiter As String = ControlChars.Tab
        Using parser As New TextFieldParser(strPriCatFile)
            parser.SetDelimiters(delimiter)

            While Not parser.EndOfData
                counter = counter + 1
                ' Read in the fields for the current line
                fields = parser.ReadFields()

                If counter = 1 Then
                    'this will be the header row we want to ignore this 
                Else
                    ' the fiels we will go ahead and parse
                    WriteData(fields(1), fields(3), fields(4), fields(6), fields(5), fields(11), fields(8), fields(9), fields(11), fields(10), fields(12), fields(13), fields(14), "t")
                End If
                Debug.Write("Records Importing" + counter.ToString())
            End While


        End Using

    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try

Write Data function

 Public Function WriteData(sUPCode As String, sColourDescription As String, sSize As String, sColorCode As String, sDivsionDescription As String, sDescription As String, sDepartment As String, sSubDeparment As String, sProductShortDescription As String, sGender As String, sProductDescription As String, sCostPrice As String, sRetailPrice As String, sDiscountedPrice As String)
    Try
        Dim pricateTableAdapter As New SkechersPricatTableAdapter()
        pricateTableAdapter.Insert(1, sUPCode, "stylenumber", sColourDescription, sSize, sColorCode, sDivsionDescription, sDepartment, sSubDeparment, sProductShortDescription, sGender, sProductDescription, sCostPrice, sRetailPrice, sDiscountedPrice)

    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try
End Function
djv
  • 15,168
  • 7
  • 48
  • 72
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • Well for starters, you have some variables your not using, the (If counter = 1 Else) statement can be fixed to (If counter > 1 Then...) because it's your header row. – Trevor Mar 20 '14 at 14:09
  • Try moving the Dim pricateTableAdapter up a level in scope - i.e module level. Look for other options for loading the source table e.g. http://stackoverflow.com/questions/1050112/how-to-read-a-csv-file-into-a-net-datatable – rheitzman Mar 20 '14 at 15:00

0 Answers0