|
 |
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 .
|
 |
|
|

March 8th, 2009, 06:46 PM
|
Friend of Wrox
|
|
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
|
|
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..
|

March 8th, 2009, 07:36 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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.
================================================== =========
|

March 8th, 2009, 08:33 PM
|
Friend of Wrox
|
|
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
|
|
Quote:
Originally Posted by gbianchi
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
|

March 8th, 2009, 08:36 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
The answer is yes, and select statement can return more than just the columns.
|

March 8th, 2009, 08:37 PM
|
Friend of Wrox
|
|
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
|
|
Quote:
Originally Posted by PeterPeiGuo
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.
|

March 8th, 2009, 08:44 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
Quote:
Originally Posted by gbianchi
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.
|

March 8th, 2009, 08:45 PM
|
Friend of Wrox
|
|
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
|
|
Quote:
Originally Posted by PeterPeiGuo
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.
|

March 8th, 2009, 08:45 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
For example:
Code:
SELECT TIMEDIFF('2000:01:01 00:00:00', '2000:01:01 00:00:00.000001');
|

March 8th, 2009, 08:57 PM
|
Friend of Wrox
|
|
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
|
|
Quote:
Originally Posted by PeterPeiGuo
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
|

March 8th, 2009, 09:32 PM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
Quote:
Originally Posted by chobo2
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 |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |