I have began a little testing and using the code below this creates a query and returns the results to tData. I have
the result showing up in a multi line text box but want the results to be formatted in a datagrid. Can anyone
explain how I could go about doing that?
on mouseUp
-- check the global connection ID to make sure we have a database connection
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
-- construct the SQL (this selects all the data from the specified table)
put the text of field "tBrand" into boo
put "[EVEREST_SOLESU].[dbo].[ITEMS]" into tTableName -- set this to the name of a table in your database
put "SELECT * FROM " & tTableName & " where brand = '" & boo & "'" into tSQL
-- query the database
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
-- check the result and display the data or an error message
if item 1 of tData = "revdberr" then
answer error "There was a problem querying the database:" & cr & tData
else
put tData into field "Data"
end if
end mouseUp
Datagrid help
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Datagrid help
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
Re: Datagrid help
Nevermind I found out from here: http://lessons.runrev.com/spaces/lesson ... Grid-Array.
I did have one question though if anyone can help me. This lesson only explains how to manually set the fields to be displayed. How can I dynamically make all the fields show up based on the table. like SELECT * from table should show all fields in the table. Is the only way to make a field show up is manually add the column tot he datagrid?
I did have one question though if anyone can help me. This lesson only explains how to manually set the fields to be displayed. How can I dynamically make all the fields show up based on the table. like SELECT * from table should show all fields in the table. Is the only way to make a field show up is manually add the column tot he datagrid?
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392
-
- VIP Livecode Opensource Backer
- Posts: 163
- Joined: Tue Jan 26, 2010 10:15 pm
- Contact:
Re: Datagrid help
Jesse,jesse wrote:Nevermind I found out from here: http://lessons.runrev.com/spaces/lesson ... Grid-Array.
I did have one question though if anyone can help me. This lesson only explains how to manually set the fields to be displayed. How can I dynamically make all the fields show up based on the table. like SELECT * from table should show all fields in the table. Is the only way to make a field show up is manually add the column tot he datagrid?
You can create dynamically the columns of a datagrid before to populate it.
1) First you need to get the names of the fields in the datagrid.
Assuming you have applied the lesson to your needs, you can use the variable theFields of the ConvertSQLCursorToArray handler.
Or you can write your own function:
Code: Select all
function fieldsFromCursor pCursor, pSeparator
put revDatabaseColumnNames(pCursor) into tTheFieldsName
if (pSeparator is not comma) then
replace comma with pSeparator in tTheFieldsName
end if
return tTheFieldsName
end fieldsFromCursor
Code: Select all
set the dgProp["columns"] of group "datagrid 1" to fieldsFromCursor(pCursor, return)
Code: Select all
set the dgProp["columns"] of group "datagrid 1" to theFields
3) Populate the datagrid:
Code: Select all
set the dgData of group "DataGrid 1" to theDataGridArray
Untested but should works.
Regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel
Re: Datagrid help
Thanks that helped get me in the right direction!
Deving on WinVista Home Prem. SP2 32 bit. Using LiveCode 4.6.1 Pro Build 1392