Page 1 of 1

Please help. Datagrid Form not showing any data

Posted: Tue Oct 06, 2015 6:28 am
by Jannie
I am having difficulty with getting the Datagrid to work.

I need to display a list of users with their user names and pictures in a datagrid.

I have followed all the tutorials and am pretty sure i am doing everything correctly.

I have created the datagrid.
I have selected form under style
I have edited the row template as per the instructions in various tutorials and videos
I coded the fillindata and other revelant row behaviors.

Still nothing shows up in my datagrid?

See the code below. (to simplify i am not trying to show the picture just the data field called UserName)

on FillInData theDataGridArray

global gConnectionID, gDetailList



put revOpenDatabase( "ODBC" ,"DRIVER=SQL Server;SERVER=L0610023709\SQLEXPRESS;DATABASE=POT;UID=sa;PWD=g66n85j03;Trusted_Connection=No" ,,,) into gConnectionID

put "SELECT UserName FROM PotUser" into tDetails

put revQueryDatabase( gConnectionID, tDetails) into gDetailList



ConvertSQLCursorToArray gDetailList, theDataGridArray

lock screen

set the dgData of group "DataGrid 1" of me to theDataGridArray

set the dgHilitedLines of group "DataGrid 1" of me to 1

repeat with x = 1 to 2

set the text of field ("UserName" ) of me to theDataGridArray[x]["UserName"]

##answer theDataGridArray[x]["UserName"]

end repeat

unlock screen

revCloseCursor gDetailList

revCloseDatabase gConnectionID


end FillInData

command ConvertSQLCursorToArray pCursor, @pOutArrayA

local i

local theFields

local theError



## Get the names of all the columns in the database cursor

put revDatabaseColumnNames(pCursor) into theFields

if theFields begins with "revdberr," then

put item 2 to -1 of theFields into theError

end if



if theError is empty then

put 0 into i

## Loop through all rows in cursor

repeat until revQueryIsAtEnd(pCursor)

add 1 to i



## Move all fields in row into next dimension of the array

repeat for each item theField in theFields

put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[ theField ]



end repeat



revMoveToNextRecord pCursor

end repeat

end if



return theError

end ConvertSQLCursorToArray

Re: Please help. Datagrid Form not showing any data

Posted: Tue Oct 06, 2015 1:10 pm
by Klaus
Hi Jannie,

1. welcome to the forum! :D
2. Please only ONE thread per problem!
I deleted the double posting from the other forum!

There are many, many problems in your scripts!
a. The "fillindata" handler is sent to the datagrid for EVERY "line" of data
so you are querying the database N times, where N is the number of records
in your table, not a good idea!

b. The parameter that comes with "fillindata" is a ONE dimensional array and
only holds the data for "this" recored, so treating it as a multidimenisonal array
will of course fail and result in an empty datagrid.

I highly recommend to work through the datagrid docs and get familiar with the
VERY complex beast called Datagrid, load a PDF here: http://lessons.runrev.com/m/datagrid

Not knowing the structure of your datagrid, so this may not work as exspoected, but try this:
1. This should go into the "Row Behavior" script of your datagrid:

Code: Select all

on FillInData theDataGridArray      
      set the text of field ("UserName" ) of me to theDataGridArray["UserName"]   
end FillInData
2. Put this into the card script of the card with the datagrid:

Code: Select all

command ConvertSQLCursorToArray pCursor, @pOutArrayA
   local i
   local theFields
   local theError   
   ## Get the names of all the columns in the database cursor
   put revDatabaseColumnNames(pCursor) into theFields
   if theFields begins with "revdberr," then
      put item 2 to -1 of theFields into theError
   end if
   
   if theError is empty then
      put 0 into i
      ## Loop through all rows in cursor
      repeat until revQueryIsAtEnd(pCursor)
         add 1 to i         
         ## Move all fields in row into next dimension of the array
         repeat for each item theField in theFields
            put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]       
         end repeat
         revMoveToNextRecord pCursor
      end repeat
   end if 
   return theError
end ConvertSQLCursorToArray
3. I created a handler that will open the database, get all your records,
convert to ARRAY and finally set the DGDATA of your datagrid.

You could "call" it in a "opencard" handler or in a button in a "mouseup" handler:

Code: Select all

command get_database_data
   global gConnectionID, gDetailList
   put revOpenDatabase( "ODBC" ,"DRIVER=SQL Server;SERVER=L0610023709\SQLEXPRESS;DATABASE=POT;UID=sa;PWD=NEVER POST A POSSIBLY VALID PWD!!!!!;Trusted_Connection=No" ,,,) into gConnectionID
   put "SELECT UserName FROM PotUser" into tDetails
   put revQueryDatabase( gConnectionID, tDetails) into gDetailList  
   ConvertSQLCursorToArray gDetailList, theDataGridArray
   revCloseCursor gDetailList
   revCloseDatabase gConnectionID
   set the dgData of group "DataGrid 1" of me to theDataGridArray
   set the dgHilitedLines of group "DataGrid 1" of me to 1
end get_database_data
Again:
This is out of my head and may not exactly fit your situatzion/stack, but you get the picture!


Best

Klaus

Re: Please help. Datagrid Form not showing any data

Posted: Tue Oct 06, 2015 2:21 pm
by Jannie
Thank you Klaus, i will try your suggestions and se where it leads me.

regards

Re: Please help. Datagrid Form not showing any data

Posted: Tue Oct 06, 2015 3:24 pm
by Jannie
Hi Klaus

I am busy going through the PDF as you recommended.

I have changed my code according to your suggestion, however when i step through the code fillidata never gets invoked.

What am i missing here?

Re: Please help. Datagrid Form not showing any data

Posted: Tue Oct 06, 2015 3:51 pm
by Klaus
Hi Jannie,

hm, hard to say from afar...
The "fillindata" handler will get invoked after you "set the dgdata of grp xyz to AnArray".

Are you sure the resulting ARRAY from "ConvertSQLCursorToArray" is not empty?
And you put the "fillindata" handler into the "Row behavior" script of the datagrid?


Best

Klaus

Re: Please help. Datagrid Form not showing any data

Posted: Fri Oct 09, 2015 6:31 am
by Jannie
Hi Klaus

Thanks for the help so far.

From the attachment you will see that the Array is populated. Still when setting the dgData of my datagrid fillindata does not get invoked.

Any ideas? maybe a bug?

Regards

Re: Please help. Datagrid Form not showing any data

Posted: Fri Oct 09, 2015 11:36 am
by Klaus
Hi Jannie,

sorry, you need to have at least 10 postings before you can post files and links here.


Best

Klaus