Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2008, 03:09 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Your code in your first post should work fine (the bit at the top - I haven't fully reviewed the rest).

i.e.

Code:
DataSet ds = GetDataset();

dataGrid1.DataSource = ds;
dataGrid1.DataBind();
You can actually assign quite a lot of things to the DataSource property, including a DataTable, or even a List or Array (anything that implements ICollection interface infact).

/- Sam Judson : Wrox Technical Editor -/
 
Old April 23rd, 2008, 03:12 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

DataTable.Rows property is an array of DataRow objects, e.g. myTable.Rows[1].

DataRow can be used like an array to look up columns, e.g. myRow["Column1"] or myRow[1].


/- Sam Judson : Wrox Technical Editor -/
 
Old April 23rd, 2008, 03:32 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yep what I need is to show all the content of the DataTable on rows in 4 rows to be precisly and play with them to show what I want. So, How can I apply that on my code?

Thanks for your responding

Regards,

Codeman1234

 
Old April 23rd, 2008, 03:34 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do I put that code after the myAdapter.Fill(myTable);??

Regards,

Codeman1234

 
Old April 23rd, 2008, 07:34 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm sorry - I don't know what you mean by the comment "show all the content of the DataTable in 4 rows and play with them to show what I want".

The DataTable will contain all the rows and fields returned by your query. If you only want to show certain columns then you could change your SQL so instead of doing "select * "... you do "select column1, column4, column5 "...

Can you explain your requirements in more detail.

/- Sam Judson : Wrox Technical Editor -/
 
Old April 23rd, 2008, 09:07 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by samjudson
 I'm sorry - I don't know what you mean by the comment "show all the content of the DataTable in 4 rows and play with them to show what I want".

The DataTable will contain all the rows and fields returned by your query. If you only want to show certain columns then you could change your SQL so instead of doing "select * "... you do "select column1, column4, column5 "...

Can you explain your requirements in more detail.

/- Sam Judson : Wrox Technical Editor -/
Hi Sam,

First Thanks for responding.
Now let me explain you in that data table I got the following information about this editorial of magazines

1) The year of the magazine
2) The Number of the magazine
3) The Trimester was publish the magazine

4) After the magazines I got the same info for suplements of the magazines.

it looks like this

2006 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

        supl. 1 supl. 2 supl. 3 supl.4
       Jan/March April/June July/Sept Oct/Dic

2005 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

        supl. 1 supl. 2 supl. 3 supl.4
       Jan/March April/June July/Sept Oct/Dic

So, I mean by playing with the data and show it in rows is that I need to show the data this way order like that.

Regards,

Codeman1234

PD: if you have any doubts tell me, thanks very much !!
:)

 
Old April 23rd, 2008, 09:24 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem I got is that it shows the following:

2088 Jan / March Jan / March Jan / March Jan / March

2008 Jan / March Jan / March Jan / March Jan / March

2007 Jan / March Jan / March Jan / March Jan / March

2007 Jan / March Jan / March Jan / March Jan / March

2007 April / June April / June April / Junè April / June

2007 April / June April / June April / Junè April / June

2007 July / Sep July / Sep July / Sep July / Sep

2007 Oct / Dic Oct / Dic Oct / Dic Oct / Dic


Doest show if it is magazine or suplement and repets in every row the same trimsester.

You see what I mean?

Regards,

Codeman1234

 
Old April 24th, 2008, 04:49 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Either that or I was thinking on doing a Store procedure that takes me out the following data just once the year, if is magazine or suplement, the number of the magazine, the number of the magazine or suplement, the trimester something like this for every year so every year I call the store procedure and change the year only, something like the following:


2006 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

        supl. 1 supl. 2 supl. 3 supl.4
       Jan/March April/June July/Sept Oct/Dic

2005 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

        supl. 1 supl. 2 supl. 3 supl.4
       Jan/March April/June July/Sept Oct/Dic

2004 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

2003 mag. 1 mag. 2 mag. 3 mag.4
       Jan/March April/June July/Sept Oct/Dic

How Can I do something like that with a store procedure, any ideas??

Thanks for responding,

kind regards,

Codeman1234




 
Old April 24th, 2008, 05:25 AM
Authorized User
 
Join Date: Apr 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got the following code for the store procedement query

CREATE PROCEDURE dbo.sp_GetRevistasXAnio
(
    @VOL_ANNO INT,-- The year print the magazine (1999 - 2008)
    @REV_TIPO_REVISTA CHAR(1),-- If it is a Suplement or Magazine (S or R)
    @REV_ID_TRIMESTRE SMALLINT,-- TRIMESTER DEL AÑO PUBLICADA LA REVISTA (1 - 4)
    @TRI_NOMBRE_TRIMESTRE_ES VARCHAR(25)-- TRIMESTRE DEL AÑO PUBLICADO DE LA REVISTA(Enero/Marzo - Abril/Junio)
)
AS
BEGIN
--REV_ID_REVISTA= ID De la Revista
--REV_NUMERO_REVISTA= El numero publicado de la revista

SELECT TOP 100 PERCENT V.VOL_ANNO, R.REV_TIPO_REVISTA, R.REV_ID_TRIMESTRE, T.TRI_NOMBRE_TRIMESTRE_ES, R.REV_ID_REVISTA, R.REV_NUMERO_REVISTA
FROM REV_REVISTAS R
    INNER JOIN TRI_TRIMESTRES T ON R.REV_ID_TRIMESTRE=T.TRI_ID_TRIMESTRE
    INNER JOIN VOL_VOLUMENES V ON R.REV_ID_VOLUMEN=V.VOL_ID_VOLUMEN
WHERE V.VOL_ANNO = 2005
    AND R.REV_TIPO_REVISTA = @REV_TIPO_REVISTA
    AND R.REV_ID_TRIMESTRE = @REV_ID_TRIMESTRE
    AND T.TRI_NOMBRE_TRIMESTRE_ES = @TRI_NOMBRE_TRIMESTRE_ES
GROUP BY V.VOL_ANNO, R.REV_ID_TRIMESTRE, R.REV_TIPO_REVISTA, T.TRI_NOMBRE_TRIMESTRE_ES, R.REV_ID_REVISTA, R.REV_NUMERO_REVISTA
ORDER BY V.VOL_ANNO DESC, R.REV_TIP

END

For the year 2005.

You know what I am doing wrong??

Regards,

Codeman1234

 
Old April 24th, 2008, 05:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The technique you are talking about is known as Pivoting (or Pivot Tables).

Basically you are trying to take the following format:

Col1, Col2, Data
A, A, 1
A, B, 2
A, C, 3
B, A, 4
etc..

into

    A, B, C
A, 1, 2, 3
B, 4, 5, 6
etc..

Unfortunately there is no easy way in a single SQL statement to perform this transformation, so yes, a Store Procedure might help.

/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
sql query i need seearam MySQL 7 November 30th, 2008 03:14 AM
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
SQL Query!! dpkbahuguna Beginning VB 6 5 October 12th, 2007 12:39 AM
Help with SQL query sattaluri Access 2 August 11th, 2006 09:26 AM
SQL query PinkyCat Classic ASP Databases 3 March 11th, 2005 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.