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 "no match" & "<br />"
'add a record
rsGaugeInfo.AddNew
rsGaugeInfo.Fields("ID")= tmpArray(0)
rsGaugeInfo.Fields("NAME") = tmpArray(1)
rsGaugeInfo.Fields("DATEUPDATE") = arrDateTime(0)
rsGaugeInfo.Fields("TIMEUPDATE") = arrDateTime(1)
rsGaugeInfo.Fields ("GAUGEHT") = tmpArray(3)
Else
response.write "match" & "<br />"
'the gauge is already in the db, just need to update data
rsGaugeInfo.Fields("DATEUPDATE") = arrDateTime(0)
rsGaugeInfo.Fields("TIMEUPDATE") = arrDateTime(1)
rsGaugeInfo.Fields("GAUGEHT") = tmpArray(3)
End If
**** END LOOP ***
rsGaugeInfo.UpdateBatch