Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2007, 10:35 AM
Authorized User
 
Join Date: Jul 2007
Location: Austin, Texas, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Gridview/repeating data

I have created a gridview that presents data from two DB tables from a specified date range. All the data is correct except that the date in the 'activity_date' column is repeated. It only shows the 'to date' of the date range that was specified. The 'filldata' method is loading the data to my tempList table correctly. I know this because each row has a unique key field being displayed, and I 'watched' the activity_date using the breakpoint as it was being loaded. Here is my code:

[u]the 'getlist' method:</u>

       public static ParticipationActivityList GetList(String emp_id, String fromDate, String toDate)
        {
            //throw new System.NotImplementedException();
            ParticipationActivityList tempList = null;
            using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrin gs["CAPSConnectionString"].ConnectionString))
            {
                SqlCommand mySqlCommand = new SqlCommand("partAct", myConnection);
                mySqlCommand.CommandType = CommandType.StoredProcedure;
                mySqlCommand.Parameters.AddWithValue("@emp_id", emp_id);
                mySqlCommand.Parameters.AddWithValue("@from_date", fromDate);
                mySqlCommand.Parameters.AddWithValue("@to_date", toDate);

                myConnection.Open();
                using (SqlDataReader myReader = mySqlCommand.ExecuteReader())
                {
                    if (myReader.HasRows)
                    {
                        tempList = new ParticipationActivityList();
                        while (myReader.Read())
                        {
                            tempList.Add(FillDataRecord(myReader));
                        }
                    }
                    myReader.Close();
                }
            }
            return tempList;
        }

[u]the 'filldata' method:</u>

        private static ParticipationActivity FillDataRecord(IDataRecord myDataRecord)
        {
            ParticipationActivity myParticipationActivity = new ParticipationActivity();
            myParticipationActivity.actv_id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("act v_id"));
            myParticipationActivity.actv_dt = myDataRecord.GetDateTime(myDataRecord.GetOrdinal(" actv_dt"));
            myParticipationActivity.actv_dscr = myDataRecord.GetString(myDataRecord.GetOrdinal("ac tv_dscr"));
            myParticipationActivity.emp_id = myDataRecord.GetString(myDataRecord.GetOrdinal("em p_id"));
            myParticipationActivity.actv_type_cd = myDataRecord.GetString(myDataRecord.GetOrdinal("ac tv_type_cd"));
            myParticipationActivity.prtpt_actv_id = myDataRecord.GetInt32(myDataRecord.GetOrdinal("prt pt_actv_id"));
            return myParticipationActivity;
        }

Let me know if more info is needed for this.

Thanks!

Richard Lelle
Austin, Tx USA
__________________
RLELLE
Reply With Quote
  #2 (permalink)  
Old July 17th, 2007, 12:46 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Richard,

Not sure I understand the problem.

Can you give a quick example of the resultset of partAct and the actual data in the GridView. I don't understand what you mean with "It only shows the 'to date' of the date range that was specified.".

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old July 17th, 2007, 01:35 PM
Authorized User
 
Join Date: Jul 2007
Location: Austin, Texas, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I have a table with 'activity' data in it, and each record in the table has an 'activity date'. If I enter a date range of 'from' 01/01/2007 'to' 12/31/2007, the gridview will present all the activity data from a table within that range, sorted by date. But, for each row of data that is presented, the activity date that is shown is 12/31/2007, instead of the activity date of that record. The activity date for that record should be shown in the date column.

Richard Lelle
Austin, Tx USA
Reply With Quote
  #4 (permalink)  
Old July 17th, 2007, 01:39 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

But how does your resultset from the database look like?

Did you try running the procedure in the query analyzer?

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #5 (permalink)  
Old July 17th, 2007, 03:42 PM
Authorized User
 
Join Date: Jul 2007
Location: Austin, Texas, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, the query analyzer gives me the exact results expected. It shows the appropriate activity_date for each row that it returns.

Richard Lelle
Austin, Tx USA
Reply With Quote
  #6 (permalink)  
Old July 17th, 2007, 04:44 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

But *how* does your data look like? How does the result set look like and what do you see in your GridView. What exactly are the differences? I still don't understand your mismatch so I don't know what to suggest.....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #7 (permalink)  
Old July 18th, 2007, 07:21 AM
Authorized User
 
Join Date: Jul 2007
Location: Austin, Texas, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for not being clear enough....I should have done this in the beginning.

When I tested the stored procedure in the query analyzer, it gave these results:

act_dt act_cd description
05/01/2007 1 carpool
05/01/2007 2 walk to lunch
05/02/2007 1 carpool
05/02/2007 2 walk to lunch
05/03/2007 1 carpool
05/03/2007 2 walk to lunch

When I run my app, the gridview presents this:

act_dt act_cd description
05/03/2007 1 carpool
05/03/2007 2 walk to lunch
05/03/2007 1 carpool
05/03/2007 2 walk to lunch
05/03/2007 1 carpool
05/03/2007 2 walk to lunch



Richard Lelle
Austin, Tx USA
Reply With Quote
  #8 (permalink)  
Old July 18th, 2007, 07:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yes exactly, that's why I was asking for it since the beginning... ;)

I can't see anything wrong with the code that would cause this issue. One thing I noticed that the column headers in your result set are called act_dt while your data object and column are called actv_dt.

If I were you, I'd set a break point on

  myReader.Close();

and then look at tempList using the Watch window. If the dates are OK there, then there might be some code in your ASPX page that is messing with the dates, or maybe you're binding the grid to a different column.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #9 (permalink)  
Old July 18th, 2007, 07:59 AM
Authorized User
 
Join Date: Jul 2007
Location: Austin, Texas, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

great idea on the 'watch' stuff.... Seeing something odd: the '05/03/2007' date is being loaded for every record. AND, I get a message in the watch window saying: "the name 'actv_dt' does not exist in the current context". So, I'm guessing that actv_dt is not declared or defined properly somewhere. I may actually have it defined as a string in my BO class, and as a datetime in my DB class.

fyi - the column header 'act_dt' was just typed that way for discussion purposes.

Richard Lelle
Austin, Tx USA
Reply With Quote
  #10 (permalink)  
Old July 18th, 2007, 08:04 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

actv_dt by itself is probably not acceptable.

Inside FillDataRecord, you can try to watch myParticipationActivity.actv_dt instead. You'll need to set an additional breakpoint in the FillDataRecord method.

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeating data ph0neman Classic ASP Basics 5 January 18th, 2008 12:34 PM
Data Binding - Editing GridView Row Data desk_star BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 7 December 30th, 2007 11:07 AM
repeater repeating in horizontal (data in 2 colums gbianchi ASP.NET 2.0 Professional 0 April 11th, 2007 11:08 AM
Get data From GridView whitewolf5 ASP.NET 2.0 Basics 0 September 1st, 2006 08:19 AM
Dynamic data in Gridview lukemack ASP.NET 2.0 Basics 8 May 26th, 2006 03:37 PM



All times are GMT -4. The time now is 11:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.