Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
selectQry = "select t2.tableName as 'Table Name',t2.gametype as 'Limit',Convert(varchar,Convert(numeric(18,2),t2.smallblind)) + '/' + Convert(varchar,Convert(numeric(18,2),t2.bigblind)) as 'Stakes',t3.GameName as 'Game Name'from tblgameinfo t1 join tblGameTables t2 on (t1.tableid=t2.tableid) join tblGames t3 on (t3.gameid = t1.gameid) where (t2.skinid= 6 or t2.skinid= 0) and t1.nickname = '" + nickname + "' order by nickname";


SQL
selectQry1 = "Select t2.tablename as'Table Name',t1.TableID as 'Table ID',t1.TournamentID as 'Tournament ID',t3.TournamentName'Tournament Name'from tblRegistration t1 join tblGameTables_TRMNT t2 on t1.TableID=t2.TableID join tblTournaments t3 on t3.tournamentID=t1.TournamentID where t3.skinid= " + SkinID + " and t1.nickname='" + nickname + "' AND t1.Eliminated='N' and t1.TableID >-1 and t3.State='P' and t3.TournamentType='S'";


these are two sql queries..! these are working properly but now i want to show result of both queries at run time in data grid view..! there are different columns name but i dont need to show it in grid viev! only data shoud be displayed in grid view of both queries..! is that possible if yes pls give me a solution...!

Note:= client needs to show data of both quaries at runtime in a grid view in one single time..!
Thanking you...
Dnyanesh Wahiley
Posted
Updated 19-Feb-12 22:39pm
v2

 
Share this answer
 
Comments
Dnyanesh Wahiley 20-Feb-12 4:37am    
sir actually i did Column Header visible propert false...! and it working but what i want just show the differnt queries data at one single time!
CRDave1988 20-Feb-12 5:46am    
In single grid view?
Dnyanesh Wahiley 20-Feb-12 6:02am    
in single grid view means...! there is not other gridview! two different queries data show in same time within a one grid view! or we can say how we will make a select statement on the basis of 2 predifined queries..! if i 'll use join over there then columns will be increased!
Hey,
it's possible create temporary Datatable add 4 columns with appropriate name
and add rows from both tables in temp table and finally set as datasourse of that gridview.
Best luck
 
Share this answer
 
Comments
Dnyanesh Wahiley 20-Feb-12 4:55am    
No buddy...! it will conflicted! and thare are heavy weight of tables so in that case if i m going to changes over there in some tables is possibility to raise a problem..! my complete database is in Normalize manner!
Nilesh Patil Kolhapur 20-Feb-12 5:00am    
so if there is any relation between two tables then try to make a single query with appropriate join it will easier
Dnyanesh Wahiley 20-Feb-12 5:11am    
yes Nilesh..! what the exact problem if u c in both queries u will found different column names...! but whatever i mentioned in select statement data would be fetch on the basis of that requirments...! it means there i want to write a one single queary where both queries columns should be identified same..!
You can create one stored procedure and in same stored procedure you can declare one table variable, you can insert result sets of both queries into this table variable.
After inserting data to your table variable you can select record from table variable.
Code snippet for declaring and inserting data to table variable is as below

SQL
DECLARE @ProductTotals TABLE
(
--Change your column name and type as per your need
  ProductID int,
  Revenue money
)
--Insert results of your first table
INSERT INTO @ProductTotals (ProductID, Revenue)
SELECT ProductID, SUM(UnitPrice * Quantity)
FROM OrderDetails1
GROUP BY ProductID
--Insert results of your second table 
INSERT INTO @ProductTotals (ProductID, Revenue)
SELECT ProductID, SUM(UnitPrice * Quantity)
FROM OrderDetails2
GROUP BY ProductID

--Last step to select data
SELECT * FROM @ProductTotals


This T-SQL code snippet is for your reference only, change your datatype and column name of table variable as per your need

Hope this will help you. If it works fine accept the solution otherwise revert back to me with your queries.
Thanks
 
Share this answer
 
v3
Comments
Nilesh Patil Kolhapur 20-Feb-12 5:03am    
yes this also fine solution but some load over db server
Dnyanesh Wahiley 20-Feb-12 5:12am    
ya Jai..! what the exact problem if u c in both queries u will found different column names...! but whatever i mentioned in select statement data would be fetch on the basis of that requirments...! it means there i want to write a one single queary where both queries columns should be identified same..!
jai000 20-Feb-12 5:18am    
Another way is that you can bind your data without using DataSource property of DataGridView. Kindly refer the following link for same
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx[^]
By using Union ALL Operator it will fine..!
here i have to do some changes in the queary because there are some rules when we combine 2 queries using Union keywords..!

Rules to union data:

•Each query must have the same number of columns
•Each column must have compatible data types
•Column names for the final result set are taken from the first query
•ORDER BY and COMPUTE clauses can only be issued for the overall result set and not within each individual result set
•GROUP BY and HAVING clauses can only be issued for each individual result set and not for the overall result set...!



select t2.tableName as 'Table Name',t2.gametype as 'Limit',Convert(varchar,Convert(numeric(18,2),t2.smallblind)) + '/' + Convert(varchar,Convert(numeric(18,2),t2.bigblind)) as 'Stakes',t3.GameName as 'Game Name'
from tblgameinfo t1 join tblGameTables t2 on (t1.tableid=t2.tableid) join tblGames t3 on (t3.gameid = t1.gameid)
where (t2.skinid= 6 or t2.skinid= 0) and t1.nickname = 'Player1' --order by nickname


union all


Select t2.tablename as'Table Name',t1.TableID as 'Limit',t1.TournamentID as 'Stakes',t3.TournamentName'Game Name'
from tblRegistration t1 join tblGameTables_TRMNT t2 on t1.TableID=t2.TableID join tblTournaments t3 on t3.tournamentID=t1.TournamentID
where t3.skinid= 6 and t1.nickname='Player1' AND t1.Eliminated='N' and t1.TableID >-1 and t3.State='P' and t3.TournamentType='S'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900