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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor question

Status
Not open for further replies.

warik

Programmer
Jun 28, 2002
169
0
0
ID
Can I do this with SQL?


a=1
use mytable && contain: number,name field
set order to number
seek(a)
if found()
messagebox("found it")
else
messagebox("nope")
endi


what I already done :


a=1
select * from mytable where number=a into my cursor


than what shuld I do next with the cursor mycursor? I use VFP5

Thank you in advance
 
Hi Warik !
Do you want the same what in the frst code ?

select mycursor
if reccount()<>0
messagebox(&quot;found it&quot;)
else
messagebox(&quot;nope&quot;)
endif



Monika from Warszawa (Poland)
(monikaiz@o2.pl)
 
Warik,

After you have run the SELECT, the cursor will contain the record that you were looking for, or it will be empty if the record does not exist.

You can test for that by doing:

IF RECCOUNT(&quot;MyCursor&quot;) > 0
messagebox(&quot;found it&quot;)
else
messagebox(&quot;nope&quot;)
endif

However, in this case, the SELECT has no advantage over the SEEK. I see no reason not to stay with your original code.

Mike



Mike Lewis
Edinburgh, Scotland
 
Monikai and Mike, if I'm not wrong, what you are doing is counting mycursor record, but it's ok too for me.

Well, let me change the question. My problem with something like this :


a=1
use mytable && contain: number,name field
set order to number
seek(a)
if found()
iname=name
messagebox(&quot;Name is :&quot;+iname)
endi


can I do than with mycursor starting from this SQL :

a=1
select name from mytable where number=a into my cursor


I need something like this:

iname=select name from mytable where number=1
messagebox(&quot;Name is :+iname)

(of couse this code can not run)

thank's in advance
 
Hi!
select mycursor
if reccount()<>0
go top &&first for number=1
iname=mycursor.name
messagebox(&quot;Name is :+iname)
else
messagebox(&quot;nope&quot;)
endif

regards


Monika from Warszawa (Poland)
(monikaiz@o2.pl)
 
Warik,

OK, you want something like this:

a=1
select name from mytable where number=a into mycursor
if reccount > 0
iname=MyCursor.name
messagebox(&quot;Name is :&quot;+iname)
endif

Couple of points: Don't put a space between my and cursor; and Name isn't a very good choice for a field name, as it is a FoxPro keyword.

Mike


Mike Lewis
Edinburgh, Scotland
 
Yes Monikai and Mike, now I understand how to use the cursor at my probelem. And also thank's for your point.

Thank you very much for you all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top