If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > [ V FoxPro] Sql Cursor problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-04, 04:14
jeoff jeoff is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
Question [ V FoxPro] Sql Cursor problem

I'm just beginning with Visual FoxPro my training course so i would like a little help about those lines.

I've got a table named "table1" which contains my primarykey :
idclient and some fields which contains strings : nomclient, departement.

I would like to make a cursor so as to select the max idclient, increment it by 1 and then add a new line to table1 with this number as primarykey.

It's not the quickest way to do but as i'm training myself before developping my application, i would like to accustom myself with a maximum of solutions for the future.

Here is the code i got when i press my button:

Create Cursor ident (idclient I(4))
Append Blank

&&this one is not accepted so i tried an other one bellow
Insert into ident (idclient) values (Select max(idclient) from table1)
&&

&& Here cant find ident when executing O_o neither if i replace ident with ident.idclient
Insert into table1 (idclient) Values (ident)
&&


Edit: I've just tried this and it works as well

Select (max(idclient)+1) from table1 into array res
Insert into table1 (idclient,activite,nom) Values (res,"","")


Question 2 : My views are not up to date while executing when i refresh it ... Why?

Last edited by jeoff; 04-08-04 at 04:32.
Reply With Quote
  #2 (permalink)  
Old 04-08-04, 05:02
zeus77 zeus77 is offline
Registered User
 
Join Date: Mar 2004
Location: Venice,Italy
Posts: 20
Quote:
Insert into ident (idclient) values (Select max(idclient) from table1)
pay attention, this form is avaible only on vfp8+

I found out that the quickest way is to use the array (I normaly use vfp6),for example I should use:

dimension aRes(3)

aRes[1]=0
aRes[2]=""
aRes[3]=""

select max(idclient)+1,"","" from table1 into array aRes

insert into table1 from array aRes

the init fase is necesary because if the table is empty it give you only a empty array...
this way is usefull even when you have to insert more lines...
Reply With Quote
  #3 (permalink)  
Old 04-08-04, 05:27
jeoff jeoff is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
Wink

thanks a lot

I hope not to spend 1 hour finding documentation each time i need to write a querry .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On