Cannot ADDNEW

  • Thread starter Thread starter John Whitworth
  • Start date Start date
J

John Whitworth

Not sure I'm posting in exactly the right group here, but I'm sure this
won't be completely OT! ;-)

I have the following piece of code on an ASP webpage. I basically want
to maintain a hitcount on an Access DB. So I determine whether a count
exists already, using the SQLQuery. If it does, I simply add one, and
update that record. If it doesn't exist, however, I attempt to add a
record. That won't work. It is the ADDNEW command that is causing the
crash, so I'm sure this is something quite fundamental.

BTW - FileStub is a 4-char field, Type is a 1-char, and Number is a
3-char. These just form the name of the JPG displayed on a particular page.

Any help would be greatly appreciated.

Thanks

John


<%
DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.Mappath("fpdb\hits.mdb") & ";"

Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open(DSN)

Set rsHitCount = Server.CreateObject("ADODB.Recordset")
rsHitCount.CursorType = adOpenForwardOnly

SQLQuery = "SELECT * FROM HitCount WHERE FileStub = '"
SQLQuery = SQLQuery & strFileStub & "' AND Type ='"
SQLQuery = SQLQuery & FlagImageType & "' AND Number ='"
SQLQuery = SQLQuery & RawImageDisplay & "'"

rsHitCount.LockType = 3
rsHitCount.open SQLQuery, OBJdbConnection

If Not rsHitCount.EOF Then
NumHit = rsHitCount("Hits")
NumHit = NumHit + 1
rsHitCount.Fields("Hits") = NumHit
rsHitCount.Update
' Response.Write(NumHit)
Else
rsHitCount.AddNew
rsHitCount.Fields("FileStub") = strFileStub
rsHitCount.Fields("Type") = FlagImageType
rsHitCount.Fields("Number")= RawImageDisplay
rsHitCount.Fields("Hits") = 1
rsHitCount.Update
' Response.Write("New!")
End If
%>
 
John said:
Not sure I'm posting in exactly the right group here, but I'm sure this
won't be completely OT! ;-)

Not to worry ... I've fixed it. My cursor type should have been 2.

Thanks for looking.

John
 
Back
Top