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

Grid on SQL Statement

Status
Not open for further replies.

Salmano

Programmer
Oct 4, 2001
34
RO
Hello !
I want my grid to be populated by a SQL statement; the code looks like this:
selectul = "Select firma, local, st, nr, bloc from firma into cursor cursorul"
with thisform.tabprinc.pag_rezult.grd_rezult
.recordsourcetype = 4 && SQL Statement
.recordsource = selectul
endwith

The problem is this: in the grid appear only the first 3 columns of 5 existing in the SQL statement; the gid is not set/forced to 3 columns only.

Thanks,
Salmano.
 
Try this:

Select firma, local, st, nr, bloc from firma into cursor cursorul
with thisform.tabprinc.pag_rezult.grd_rezult
.recordsourcetype = 1 && Aias
.recordsource = " " && Should be some spaces!!
* The grid is rebuild after assigning a new alias!
* This incase the grid had less than 5 columns!
.recordsource = 'cursorul'
endwith


Hope this helps,

Charl
 
Thanks Charl !
I did as you said, but I got the same result... that's very strange... beliving that's something wrong with the table firma, I cuted the part "into cursor cursorul", but the result is as it should be: with 5 fields !
Did you see something like that before ? i'll format c: :) kidding...
Salmano.
 
Hi Salmano,

I think the problem is that you set the same cursor name results. Try this:

local m.lcCursorname
m.lcCursorname = sys(2015)
Select firma, local, st, nr, bloc from firma into cursor (m.lcCursorname)
with thisform.tabprinc.pag_rezult.grd_rezult
.recordsourcetype = 1 && Aias
.recordsource = " " && Should be some spaces!!
* The grid is rebuild after assigning a new alias!
* This incase the grid had less than 5 columns!
.recordsource = m.lcCursorname
endwith


Let me know if this worked,

Charl
 
Hi Charl !

I tried what you said... i didn't work; I erased the grid and created another one, with it's default settings; the same result... I checked the VFP options for something strange, but I didn't notice anything wrong... how come actually the same things, in VB works and in VFP doesn't... I'll try to populate the grid with .QPR files and see what happends.

Thanks for your effort ! If you have any other ideas please let me now !

Salmano.
 
Hi Salmano,

I think the solution could be very easy:

selectul = "Select firma, local, st, nr, bloc from firma into cursor cursorul"

In the above statement you used 2 RESERVED FOXPRO KEYWORDS as a field-name.

These two words are LOCAL and BLOC (see Foxpro-Help).

I suggest to change the field-names into NON reserved words and then you could have
two more showed.

Hope that helps


Greetings from Germany.

Klaus
 
I'm thinking what the problem can be...
Maybe the problem occurs because of the column local wich is a VFP keyword for local variable. I would suggest rename this column and try it again...

Charl
 
Yes Klaus,
you where responding the same time,
but I didn't knew that bloc is also a reserved keyword?

Checking in VFP help:

BITXOR
BLANK
BLINK
BLOCKSIZE
BOF
BORDER
BORDERCOLOR
BORDERSTYLE
BORDERWIDTH
BOTTOM
BOUND
BOUNDCOLUMN
BOUNDTO
BOX

Sorry Klaus no Bloc to see? ;-)

Charl
 
Charl, I checked this syntax in my company where I do use VFP 5.0 -

When I checked it at now home (where I use VFP 6.0) I did not find BLOC either within 6.0.

I will look up the concrete meaning of BLOC tomorrow and will tell you then, as I have
no chance to approve again from here

I really know, that the syntax was marked blue, so there is a reserved word for BLOC.


Good evening so far...

Klaus
 
"bloc" is short for blocksize, as in "set blocksize to some number", used to control memo field disk space. See the commands "sys(2012)" and "set blocksize" in help.

To see the use "bloc" as a key/reserved word, from the command window:
open a table that has a memo field
then type:
?sys(2012) <enter>
?set(&quot;blocksize&quot;) <enter>
?set(&quot;bloc&quot;) <enter>
All three commands should return the same value.

 
Hi !
I have to use the &quot;bloc&quot; name, because this is the name given to the field, and it's impossible to change that !

But I tried like this, eliminating for testing the &quot;bloc&quot;:

local m.lcCursorname
m.lcCursorname = sys(2015)

Select firma.firma as my_firma, firma.st as my_strada, firma.sc as my_scara, firma.nr as my_numar, firma.ap as my_apart from firma into cursor (m.lcCursorname)

with thisform.tabprinc.pag_rezult.grd_rezult
.recordsourcetype = 1
.recordsource = &quot; &quot;
.recordsource = m.lcCursorname
Endwith


It doesn't work. I begin to think that is something wrong with my grid control. I'll try to populate it with VFP's grid wizard/builder; if that works, it means that's something I do not take into consideration...
Thanks a lot for your intersert!
Salmano.
 
Hi Klaus,

A good morning,

I'm using VFP 7.0 and the reserved keywords quoted in my last post come out the VFP 7.0 help supplied with VFP 7.0.

The strange thing is that bloc gets the blue color, and ? set(&quot;bloc&quot;) does work also set bloc to.

The question now is if it is a reserved word or not (In VFP 7.0 is seems not to be)?;-)

Explanation:
bloc = 5
* I start the debugger and bloc is displayed as a variable
* During the assignment no error occurred
? set(&quot;bloc&quot;)
* still displays 64

* I made a table with the fields id and bloc and put some test values in it.
select * from table1
* displays a browse window with all three records.
select id, bloc from table1
* displays a browse window with all three records.
use table1 again
replace bloc with 34243
use
use table 1 again
browse
* displays a browse window with all three records. And the first record field bloc contains the value 34243.

I think I may conclude that bloc is not a reserved keyword in VFP 7.0


Charl

 
Hi all !
I found out a way to obtain all the selected fields in the grid: reseting the column number; so, the code that works for me is as you said Charl, but adding
.resettodefault(&quot;ColumnCount&quot;) && = -1
line does the thing.
Thanks all for your interest.
Salmano.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top