Page 1 of 1
Multiple Database Tables into single DataGrid
Posted: Fri Mar 08, 2013 9:03 pm
by dcpbarrington
I have a database with multiple tables that are very similar that I would like to display into a single DataGrid Table.
I SELECT the values from the database and create a multi-dimensional array that easily goes into the DataGrid.
I've been looking for a way to define a column in the DataGrid and had multiple DB columns in the same column.
Data Example
Table ABC
Date
Time
ValueABC
UnitsABC
Table XYZ
Date
Time
ValueXYZ
UnitsXYZ
Can I create a DataGrid with Columns = Date, Time, Value and Units and then configure a way to display ValueABC in the Value column when TableABC is selected and ValueXYZ in the Value Column when the TableXYZ is selected.
The only way I found was to create a column for both ValueABC and ValueXYZ and then to change the visibility based on what Table is selected.
Anyone have a better option. Thanks in advance for the help.
Re: Multiple Database Tables into single DataGrid
Posted: Sat Mar 09, 2013 12:04 pm
by Klaus
Hi dcpbarrington,
I am not sure I understand, but can't you somehow combine (not the Liveocde term!

)
the two arrays with the data of each database call and THEN oput them into a datagrid?
Best
Klaus
Re: Multiple Database Tables into single DataGrid
Posted: Tue Mar 19, 2013 5:42 pm
by dcpbarrington
Klaus,
Thanks you for your response.
Wow. I think I was over complicating the situation, but thinking that I could do it as part of a column group function. Some times you just need someone else to look at the problem.
Convert the Array tags before sending them to the DataGrid so the Array Tags would match the column tags of the DataGrid.
Basically I would need to go through each element of the Array in a REPEAT loop and change the tag names of the array values.
Thank
dcpbarrington
Re: Multiple Database Tables into single DataGrid
Posted: Tue Mar 19, 2013 7:34 pm
by Klaus
Okie Dokie

Re: Multiple Database Tables into single DataGrid
Posted: Tue Mar 19, 2013 9:17 pm
by mwieder
If the two tables have the same format, a simpler thing might be to use a SQL union command. Then just throw the result into the datagrid.
Re: Multiple Database Tables into single DataGrid
Posted: Wed Apr 10, 2013 9:08 pm
by NigelS
I'm making a deduction from your question that you are referring to is doing a sql "SELECT" to get data? If this is so you can do calls within the "SELECT" command that bring the record set from all the tables into a list.
if you pop across to this link
http://forums.runrev.com/viewtopic.php?f=8&t=14672 ,look at the code snippet for this is what I actually do when I need data from more than one table
Regards
Nigel
Re: Multiple Database Tables into single DataGrid
Posted: Thu Apr 11, 2013 4:17 pm
by sturgis
Don't have time to look at it right this sec but.. first you might see if dot notation will work for you during your select.
Something like select tablename1.column,tablename2.column from tablename1,tablename2...
And also look at the "AS" option. select tablename1.date as date1,tablename2.date as date2 from tablename1,tablename2
I haven't tested, and don't know what differences there are between sqlite, mysql, postgresql etc but it might simplify things. Do a single select, teh data comes in as normal, but with headers matching the "as..." names you gave them. So the date from table 1 would have the header date1 and date2 for the date field from table 2.
As I said, haven't tested, and it is untweaked, but seems like it might be a good avenue to look at.
EDIT: Nvm the dot notation, found your other post and you're already doing that. But the select AS still might apply, and you should still be able to use your current join.