Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB.NET - OLEDB with Foxpro table

VB.NET - OLEDB with Foxpro table

Scheduled Pinned Locked Moved Visual Basic
csharphelpannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    iluha
    wrote on last edited by
    #1

    Hi! I'm trying to run a process that updates a zip/tax rate table. The new tax rates are in a flat file. the table I need to update is a FoxPro free table indexed in country and zipcode fields. Everything is working, but I have 45K+ records to update and after about 15% into the flat file the process it gets slooooow and gets slower and slower. If I comment out the code that does search and just leave the code that goes through the flat file it takes about 30 seconds with the looks up and update it takes 30+ minutes and I can see the progress bar miving for first 15% and than it dies.... I think I am missing something here... Here is what the code looks like: m_conn = New OleDbConnection m_conn.ConnectionString = "Provider=VFPOLEDB.1;" & _ "Data Source=" & g_app_options.processing_folder_path & "output\tax import;" & _ "Mode=ReadWrite|Share Deny None;" & _ "Collating Sequence=MACHINE;" m_conn.Open() Do While srTaxFile.EndOfStream = False ado_command = New OleDb.OleDbCommand("SELECT ZIPCODE FROM zip WHERE country='001' AND ZIPCODE='" & taxRecord.field(cTaxRecord.RecordFieldIDs.ZipCode).Trim & "'", m_conn) Dim sZipCode As String = ado_command.ExecuteScalar() ado_command = New OleDb.OleDbCommand("UPDATE zip SET itaxr = " & taxRecord.field(cTaxRecord.RecordFieldIDs.SalesTaxRate).Trim & " WHERE zipcode='" & taxRecord.field(cTaxRecord.RecordFieldIDs.ZipCode).Trim & "'", m_conn) ado_command.ExecuteNonQuery() set_progress(srTaxFile.BaseStream.Length, srTaxFile.BaseStream.Position) Loop Its pretty simple, and I don't understand why it takes that long. This is running on a local drive. If you can help or know what I'm missing, I would greatly appreciate it! Thank you ipokrov

    C 1 Reply Last reply
    0
    • I iluha

      Hi! I'm trying to run a process that updates a zip/tax rate table. The new tax rates are in a flat file. the table I need to update is a FoxPro free table indexed in country and zipcode fields. Everything is working, but I have 45K+ records to update and after about 15% into the flat file the process it gets slooooow and gets slower and slower. If I comment out the code that does search and just leave the code that goes through the flat file it takes about 30 seconds with the looks up and update it takes 30+ minutes and I can see the progress bar miving for first 15% and than it dies.... I think I am missing something here... Here is what the code looks like: m_conn = New OleDbConnection m_conn.ConnectionString = "Provider=VFPOLEDB.1;" & _ "Data Source=" & g_app_options.processing_folder_path & "output\tax import;" & _ "Mode=ReadWrite|Share Deny None;" & _ "Collating Sequence=MACHINE;" m_conn.Open() Do While srTaxFile.EndOfStream = False ado_command = New OleDb.OleDbCommand("SELECT ZIPCODE FROM zip WHERE country='001' AND ZIPCODE='" & taxRecord.field(cTaxRecord.RecordFieldIDs.ZipCode).Trim & "'", m_conn) Dim sZipCode As String = ado_command.ExecuteScalar() ado_command = New OleDb.OleDbCommand("UPDATE zip SET itaxr = " & taxRecord.field(cTaxRecord.RecordFieldIDs.SalesTaxRate).Trim & " WHERE zipcode='" & taxRecord.field(cTaxRecord.RecordFieldIDs.ZipCode).Trim & "'", m_conn) ado_command.ExecuteNonQuery() set_progress(srTaxFile.BaseStream.Length, srTaxFile.BaseStream.Position) Loop Its pretty simple, and I don't understand why it takes that long. This is running on a local drive. If you can help or know what I'm missing, I would greatly appreciate it! Thank you ipokrov

      C Offline
      C Offline
      CodingYoshi
      wrote on last edited by
      #2

      Sorry but are you trying to update a table based on values from a flat file? Also, why are you selecting first if you know what you want to update? You should also look at Transaction--this might make the process faster but I am sure there are better ways to do what you need to do. Can you please explain what you want to do, in plain English, without any code?

      I 1 Reply Last reply
      0
      • C CodingYoshi

        Sorry but are you trying to update a table based on values from a flat file? Also, why are you selecting first if you know what you want to update? You should also look at Transaction--this might make the process faster but I am sure there are better ways to do what you need to do. Can you please explain what you want to do, in plain English, without any code?

        I Offline
        I Offline
        iluha
        wrote on last edited by
        #3

        Hi, Sorry I was not clear on what I'm trying to do. In plain English, I have a comma delimited file with 45k+ records that contains zipcode and taxrate. I have a foxpro table that contains countrycode, zipcode and taxrate fields. Now I need to update each taxrate field in the table with value of taxrate field from the flat file. If the zipcode in taxrate table is not found I need to insert a new record. (that is why I have to lookup the zipcode first, I commented that code out and did not include it with my example.) Thank you ipokrov

        C B 2 Replies Last reply
        0
        • I iluha

          Hi, Sorry I was not clear on what I'm trying to do. In plain English, I have a comma delimited file with 45k+ records that contains zipcode and taxrate. I have a foxpro table that contains countrycode, zipcode and taxrate fields. Now I need to update each taxrate field in the table with value of taxrate field from the flat file. If the zipcode in taxrate table is not found I need to insert a new record. (that is why I have to lookup the zipcode first, I commented that code out and did not include it with my example.) Thank you ipokrov

          C Offline
          C Offline
          CodingYoshi
          wrote on last edited by
          #4

          Create a datatable of all the zipcodes which are not found in the foxpro table. For update you can use something like http://sqlblogcasts.com/blogs/simons/archive/2006/10/04/SQL-Engine---BULK-UPDATE-command.aspx[^] For the insert from the datatable to database, use SqlBulkCopy class.

          1 Reply Last reply
          0
          • I iluha

            Hi, Sorry I was not clear on what I'm trying to do. In plain English, I have a comma delimited file with 45k+ records that contains zipcode and taxrate. I have a foxpro table that contains countrycode, zipcode and taxrate fields. Now I need to update each taxrate field in the table with value of taxrate field from the flat file. If the zipcode in taxrate table is not found I need to insert a new record. (that is why I have to lookup the zipcode first, I commented that code out and did not include it with my example.) Thank you ipokrov

            B Offline
            B Offline
            Ben Fair
            wrote on last edited by
            #5

            FoxPro has indexing on it's tables using either IDX or CDX files, they'll have the same name as the .DBF file, but with a different extension; that is if there are any indexes on the table. Hopefully, there is an index on the zipcode field that can be used to speed up the look up queries. From my experience with OLEDB, it's generally faster to send as few commands as possible, so build a single query like: select zipcode from zipcodes where zipcode in (... comma-separated list of zip codes ...) This query of course will perform much better if there is an index on the zipcode field. It will give you the list of zipcodes that exist and need to be UPDATEd and ones that aren't in the result set will be INSERTs.

            Keep It Simple Stupid! (KISS)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups