Data grid with an UNION

  • Thread starter Thread starter Baranyi Peter
  • Start date Start date
B

Baranyi Peter

Hi,

I am a totally newbie to .NET, so first of allI would like to ask you some
tutorial URL-s. :).
My problem is that I have to show a list of orders with lines where I
summarise the value of them by the sorted column. So if the sort is by
customer, than the grid should contain all the orders and sum lines for
every customer. If the sort is by product, than the sum should show the sum
per product besides the normal order lines.
In Delphi I managed it with an UNION, where the first SELECT gave the normal
order records, the second the summary lines.
However if I put an UNION into the sqlDataAdapter than it is just not
showing up. What did I wrong?
Besides this I have to color the summary lines differently than the normal
lines. How can I do this?

Thanks and best regards:

Peter
 
Hi Peter,

First of all, I would like to confirm my understanding of your issue. I'm
not quite sure about your question. I would like to know which value would
you like to summarise? The total amout or the count of orders? I understand
that if the grid is sorted on customer, the value has to be summarised for
each customer, while if it is sorted on products, the value has to be
summarised for each product. If there is any misunderstanding, please feel
free to let me know.

As far as I know the UNION operater in T-SQL manages to combines the
results of two or more queries into a single result set consisting of all
the rows belonging to all queries in the union. For example, we have two
tables with the same structure, we can use the following statement to
return all the records in both two tables.

SELECT * FROM Table1 UNION SELECT * FROM Table2

So I don't think UNION can do it for you in SQL server. You can try to use
SUM or COUNT functions in T-SQL to do statistics for specific values and
write additional codes to your application to display the summaries on the
grid. Here are some links for your reference.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_
ca-co_5790.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_
setu-sus_414d.asp

To customize the colors on the DataGrid, here is a good article for your to
start.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/
html/wnf_custdatagrid.asp

Also, I have found some useful links for you to start learning .NET
framework and ADO.NET.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netstart/ht
ml/sdk_netstart.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconoverviewofadonet.asp

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi,

so: I want to summarise the value of the orders. The grid should contain
several info, like the supplyer, the customer, the product, the order date,
etc. And I have to be able to show summs on the column what the user clicks
for sorting. In other words: if the user sorts by customer, I have to show
the summ by customer. If he sorts by product, than I have to show the summ
by product. Is it more understandable?
For the time being I did this job as follows: Select * from Table UNION
select Sum(price) from Table group by xxx, order by xxx. Naturally the
second select contains several NULL's: at every column what is not the group
by, and not the price column. This second part is made dynamically: every
case when the user clicks on a column to change the sorting I change the
second SELECT to display the proper summs.
To tell you the truth, I think I have to look after a 3rd party grid
solution.... :).
I will read all the links you cited. Thanks for your help.

Peter
 
Hi Peter,

Nice to know that you have had the problem resolved. If there is anything I
can do to help you, please feel free to let me know.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top