Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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

You are currently viewing the ASP.NET 3.5 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2009, 06:46 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default How to add another Columns to gridview through C# code?

Hi

I using my sql to return back a dataset of columns however I need to add another column before I bind it to the gridview.

Basically I need one of the columns that is coming from the dataset what is a date field and find the difference between that date and the current date(todays date) and for each row add under a new column(say differenceColumn) the difference between each date.

I am not sure if I could do this write in one go or something with my sql statement if I can could I see an example of that?

I also would like to know how to add columns in C# code too.

Last edited by chobo2; March 8th, 2009 at 06:48 PM..
  #2 (permalink)  
Old March 8th, 2009, 07:36 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

You could add this directly in you SQL query (how to do it depends on the database you are using). In fact I think this is faster, because if you want to add it at the code, you will have to loop everyrow adding the value.

The function in SQL server or access is datediff, I don't remember the oracle one. You would add a column to the select part with the function and the diference between actual day (how to obtain it also depends on the database) and the column you want. and name it like you want .
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
  #3 (permalink)  
Old March 8th, 2009, 08:33 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by gbianchi View Post
You could add this directly in you SQL query (how to do it depends on the database you are using). In fact I think this is faster, because if you want to add it at the code, you will have to loop everyrow adding the value.

The function in SQL server or access is datediff, I don't remember the oracle one. You would add a column to the select part with the function and the diference between actual day (how to obtain it also depends on the database) and the column you want. and name it like you want .
I am using a mssql 2005 database. So could you right a small example of this?

Thanks
  #4 (permalink)  
Old March 8th, 2009, 08:36 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

The answer is yes, and select statement can return more than just the columns.
  #5 (permalink)  
Old March 8th, 2009, 08:37 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by PeterPeiGuo View Post
The answer is yes, and select statement can return more than just the columns.
I am not sure what you mean by a "select statement can return more than just columns"

Can I see an example or tutorial of this?

I am not that great with databases so this is new to me.
  #6 (permalink)  
Old March 8th, 2009, 08:44 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Quote:
Originally Posted by gbianchi View Post
The function in SQL server or access is datediff
He might want timediff. datediff only gives the difference in days. Well, depend on his requirement, which he didn't clearly specify.
  #7 (permalink)  
Old March 8th, 2009, 08:45 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by PeterPeiGuo View Post
He might want timediff. datediff only gives the difference in days. Well, depend on his requirement, which he didn't clearly specify.
I just want the different in days. I actually need a way to remove the time part. Like it is a TimeDate but I really only want the Date not the Time but they don't have an option that just shows Date.
  #8 (permalink)  
Old March 8th, 2009, 08:45 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

For example:
Code:
SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:01 00:00:00.000001');
  #9 (permalink)  
Old March 8th, 2009, 08:57 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by PeterPeiGuo View Post
For example:
Code:
SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:01 00:00:00.000001');
How would I mix that with other statements. Like I am grabbing other table columns

this is what I have

Code:
SELECT  Planner.CourseName, Planner.Type, Planner.Description, Planner.DueDate, Planner.Weight, PlannerSettings.CourseColor, 
                      PlannerSettings.FontColor 
FROM         Planner INNER JOIN
                      PlannerSettings ON Planner.ID = PlannerSettings.ID
WHERE     (Planner.UserID = @UserID) AND (Planner.UserName = @UserName) AND (Planner.NotifcationDate <= @date)
I tried to add what you had after my stuff but I just get errors. I used datediff though not timediff
  #10 (permalink)  
Old March 8th, 2009, 09:32 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

Quote:
Originally Posted by chobo2 View Post
I really only want the Date not the Time but they don't have an option that just shows Date.
Of course they do. For example
Code:
SELECT DATE('2003-12-31 01:02:03');
 


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
How to freeze GridView columns? MLaGrange BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 September 16th, 2010 10:10 PM
Adding columns to Gridview gagansharma7 ADO.NET 1 February 15th, 2008 10:54 AM
Need to get value of gridview template columns for kmh030 ASP.NET 2.0 Professional 1 January 6th, 2007 11:10 PM
Hyperlinks in GridView Columns monika.oberoi ASP.NET 2.0 Professional 2 December 22nd, 2006 04:21 AM



All times are GMT -4. The time now is 12:44 PM.


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