April 19, 2024, 01:17:53 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


I have broken something

Started by Rock Ridge Farm (Larry), July 10, 2008, 06:56:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rock Ridge Farm (Larry)

This was working and stopped.
I have a database with one table that has 2 fields, ID - autonumber, and server - text.
I add several records to the db.
I run the following code:

POINTER pReturn,pdbx
int dbH,hSq3,id,count
istring svr[255]

   pReturn=dbConnect("Microsoft Access Driver (*.mdb)","test.mdb",";")
   IF pReturn=NULL
      MESSAGEBOX 0,"Could not connect to OSAA database\n\nPlease check the OSAA Database path, and restart OSAA","Open Database error",@MB_ICONSTOP
     
   ENDIF
   hSq3=dbExecSQL(pReturn,"SELECT * FROM zzz ORDER BY ID")
   IF LEN(dbGetErrorCode(hSq3))
MESSAGEBOX 0,dbGetErrorText(hSq3),dbGetErrorCode(hSq3)
   ENDIF
IF DBGETLAST(hSq3)
dbBindVariable(hSq3,1,id)
dbBindVariable(hSq3,2,svr)
ELSE
MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF
MESSAGEBOX 0,str$(id),"debug"
MESSAGEBOX 0,svr,"debug"
count=dbCardinality(pReturn,"zzz")
MESSAGEBOX 0,str$(count),"debug"

It always returns 0 for the ID value. The cardnality returns the number of records.
What am I doing wrong?

LarryMc

attach a copy of your "test.mdb" and I'll see if I can make it work.

I do notice that hSq3 is declared as an int instead of an uint but don't know if that is the problem.

Larry

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Rock Ridge Farm (Larry)

It would be eaiser for you to make a new db and add the one table.
Table zzz has 2 fields as described above.
You can add data when you create the db.
An empty db is still large (~30K).
If you can not - I will email it to you.

LarryMc

July 10, 2008, 09:38:17 AM #3 Last Edit: July 10, 2008, 09:43:30 AM by Larry McCaughn
Your problem is with this section:

IF DBGETLAST(hSq3)
    dbBindVariable(hSq3,1,id)
    dbBindVariable(hSq3,2,svr)
ELSE
    MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF

You're trying to get the last record of the results before you are binding the variables which means "0" is the correct result for what you are doing.

Change it to this and it should work:
If hSq3
    dbBindVariable(hSq3,1,id)
    dbBindVariable(hSq3,2,svr)
    DBGETLAST(hSq3)
ELSE
    MESSAGEBOX 0,"Failed to get last server","ERROR"
ENDIF

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Rock Ridge Farm (Larry)

That fixed it - owe you a big thanks.
Not sure when I made the change that broke it - must have been when
I was cleaning up the code.

Allan

Found a FREE application for repairing MDB.

http://www.softales.com/index_software.php?list=61

Might be of interest.