user2690047
user2690047

Reputation: 133

VFP Grid + SQL server 2008 - grid not showing correctly

i am having a problem, i have a grid called "gridbasica" with and i do this:

Thisform.GridBase.RecordSource = "sgviemp"

sgviemp is a cursor made by executing a select to a SQLserver with the command SQLEXEC.

when i want to modify a registry, i go to another form and do the the update there. so, when i come back to the form with the grid, that grid isnt a grid anymore, is a big white rectangle.

Reading around someone said: delete the recordsource and asingt it again.

Thisform.GridBase.RecordSource = ""
*--i do my sqlexe here
Thisform.GridBase.RecordSource = "sgviemp"

I do that and it works, BUT, when i click the button modify again the cursos is updated but the modify form doesnt load the fields as it did the first time.

Could anyone help me out with that?

thanks in advance.

--------------- EDIT ------------------

i have been doing this as recommended:

lnselect = select(0)
n = SQLEXEC(thisform.conexion,"select emp_ccodigo as Codigo, emp_cnombre as 'Nombre o Razon Social', emp_cnumrif as 'R.I.F'  from sgviempr","sgviemp1")


SET ECHO on
SUSPEND

SELECT sgviemp
ZAP IN sgviemp
*-- browse  *--zaps correctly
*-- SELECT sgviemp1  
*-- browse             *-- sgviemp1  full
APPEND FROM dbf( 'sgviemp1' )
USE IN sgviemp1
*-- BROWSE *--shows sgviemp1 empty

*-- SELECT sgviemp
*-- browse *--shows sgviemp empty too

and it doesnt load anything in the grid

Upvotes: 0

Views: 567

Answers (2)

user2690047
user2690047

Reputation: 133

Error found here:

n = SQLEXEC(thisform.conexion,"select emp_ccodigo as Codigo, emp_cnombre as 'Nombre o Razon Social', emp_cnumrif as 'R.I.F'  from sgviempr","sgviemp1")

In the query, the grid sources are named emp_ccodigo ,emp_cnombre and emp_cnumrif NOT codigo, Nombre o Razon Social, or R.I.F, so needed to do remove the "as" statements. So it looks like this:

n = SQLEXEC(thisform.conexion,"select emp_ccodigo, emp_cnombre, emp_cnumrif from sgviempr","sgviemp1")

Upvotes: 0

Tamar E. Granor
Tamar E. Granor

Reputation: 3937

Don't ever destroy and recreate the cursor a grid is based on. Instead, use "Safe Select," where you create the cursor ahead of time and when you need to repopulate it, you ZAP it and APPEND the new data:

http://fox.wikis.com/wc.dll?Wiki~GridSafeSelect~Wiki

Tamar

Upvotes: 3

Related Questions