Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating a database has blank records

Status
Not open for further replies.

spiveygb

Programmer
Jun 24, 2003
27
0
0
US
My goal is to update a dBase file with updated values extracted from a text file using the 'ID' filed as the unique value. If a match isn't found, I want to add the record to the database. If there is a match, then I just want to update a couple of fields. My problem/question is that I end up with many more records that I should with many of them being blank. So, for example, if the dBase file is empty and I have to add all the contents of the text file as new records (should be 250 of them), I end with a file consisting of approx. 750 records (first 500 or so are blank). What is causing this behavior? Furthermore, is there any way to handle it so that I end up with the correct number of records in the dBase file? Code snippet is listed below. Thanks in advance.

Code:
'connect to the database
  Set oConn = Server.CreateObject( "ADODB.Connection" )
  ConnectString = "Driver={Microsoft Visual FoxPro Driver};" & _
          "SourceType=DBF;SourceDB=c:\;Exclusive=No;"
  oConn.Open ConnectString
  
  'create the recordset
  Set rsGaugeInfo = Server.CreateObject( "ADODB.Recordset" )  
  rsGaugeInfo.Open "Select * from USGSdata.DBF", oConn, adOpenStatic, adCmdTable

*** THIS IS ACTUALLY CONTAINED IN A LOOP THAT READS 
THE LINES OF TEXT FROM THE TEXT FILE ****
rsGaugeInfo.MoveFirst
        Dim criteria
        criteria = "ID='" & gaugeID & "'"
        rsGaugeInfo.Find criteria,,,adBookmarkFirst
  '      'if eof or bof then a match wasn't found
        If (rsGaugeInfo.BOF = True) OR (rsGaugeInfo.EOF = True) Then
          response.write &quot;no match&quot; & &quot;<br />&quot;
          'add a record
          rsGaugeInfo.AddNew     
          rsGaugeInfo.Fields(&quot;ID&quot;)= tmpArray(0)
          rsGaugeInfo.Fields(&quot;NAME&quot;) = tmpArray(1)
          rsGaugeInfo.Fields(&quot;DATEUPDATE&quot;) = arrDateTime(0)
          rsGaugeInfo.Fields(&quot;TIMEUPDATE&quot;) = arrDateTime(1)
          rsGaugeInfo.Fields (&quot;GAUGEHT&quot;) = tmpArray(3)
        Else
           response.write &quot;match&quot; & &quot;<br />&quot;
          'the gauge is already in the db, just need to update data      
          rsGaugeInfo.Fields(&quot;DATEUPDATE&quot;) = arrDateTime(0)
          rsGaugeInfo.Fields(&quot;TIMEUPDATE&quot;) = arrDateTime(1)
          rsGaugeInfo.Fields(&quot;GAUGEHT&quot;) = tmpArray(3)
        End If
**** END LOOP ***
rsGaugeInfo.UpdateBatch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top