Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 November 11th, 2003, 06:31 PM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO.net Calendar

Does anyone know how to retrieve all dates from a selectionrange :

I would like to select from 11/1/2003 to 11/7/2003 now I can put the Stop and End dates in text boxes. But I would like to place the dates 11/2, 11/3, 11/4 , 11/5, 11/6 into a Database. This will help me with certain Queries I have to create.


txtStart.Text = MonthCalendar1.SelectionRange.Start.ToShortDateStr ing
txtEnd.Text = MonthCalendar1.SelectionRange.End.ToShortDateStrin g

Please Help
Reply With Quote
  #2 (permalink)  
Old November 12th, 2003, 10:13 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Users,

What about placing the information in a ListBox? I am still trying to get the dates between the Start and Dates.. :(
Reply With Quote
  #3 (permalink)  
Old November 12th, 2003, 10:33 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

Well, if you ask me, why not store just the Start and the End data in the database? Of course I don't know about your database design but storing just the start and end date is much more efficient, and I think that in most, if not in all, cases, you can still retrieve the same data.

If you do insist on getting the date you could try something like this:

While MyLatest > MyTempDate

  MyTempDate.AddDays(1)
  Save TempDate somewhere

Loop

This way, you keep adding a day to the start date, while the value of the tempdate is still smaller than your end date.

I am sure there are lots of alternatives as well, but I think this would work pretty well.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #4 (permalink)  
Old November 12th, 2003, 11:09 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you help me sort out this code....


 txtStart.Text = MonthCalendar1.SelectionRange.Start.ToShortDateStr ing
        txtEnd.Text = MonthCalendar1.SelectionRange.End.ToShortDateStrin g

        kStart = txtStart.Text
        kStop = txtEnd.Text

        Do While kStop > kStart

            kStart.AddDays(1)
            ListBox1.Items.Add(kStart)
            'Save TempDate somewhere

        Loop

Thank you
Reply With Quote
  #5 (permalink)  
Old November 12th, 2003, 11:37 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

Sure, although it would really help if you'd describe what problems you're encountering with your code. Saves me from finding that out myself.

Anyway, this might work:
Code:
Dim dtStart As New System.DateTime(2003, 11, 1)
Dim dtEnd As New System.DateTime(2003, 11, 30)
Dim dtTemp As System.DateTime
dtTemp = dtStart
Do While dtTemp < dtEnd
  dtTemp = dtTemp.AddDays(1)
  ListBox1.Items.Add(dtTemp.ToString())
Loop
This basically sets the temp date equal to the start date, and then starts adding one day to it. As long as the temp date is smaller than the end date, a new item will be added to the Listbox.

Three things to notice: first of all, you need real data objects. You cannot add a day using AddDays to a text property, like you did in your example.
Second, this code will also add the last day (november 30). If you don't want this, you'll need to change your coding logic a bit.
Finally, I added the Integer, Integer, Integer constructor for the new System.DateTime object. If you don't have these tree numbers available, you may need to use the Convert class to convert a string to a System.DateTime, using Convert.ToDateTime, or using DateTime.Parse.

Cheers,

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #6 (permalink)  
Old November 13th, 2003, 11:05 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for all you're help
Reply With Quote
  #7 (permalink)  
Old November 13th, 2003, 11:15 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

While I have you close by can you help me declare a time.

New System.DateTime(2003, 11, 30)
is used for a date. But when I return a date from my Access Database I have a long date, which fills my Datagrid. I have Declared my time as a string, but this creates problems further down the line.

Dim KStartTime As String

Please help

Thanks
Reply With Quote
  #8 (permalink)  
Old November 15th, 2003, 05:41 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

Hi Kenneth,

Take a look at the constructors of DateTime at: http://msdn.microsoft.com/library/de...sctortopic.asp

It is possible to pass hours, minutes, seconds, and so on to a DateTime constructor to include time information.

Alternatively, like I said in my previous post, use the Convert class or the Parse method of the DateTime structure: http://msdn.microsoft.com/library/de...asp?frame=true

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #9 (permalink)  
Old November 17th, 2003, 11:43 AM
Authorized User
 
Join Date: Jun 2003
Location: Birmingham, N/a, USA.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for you help, but it seems to me like I am going to circles. I am returning information from the database, but not query the database so I can stop users from reserving the same space that has previously been reserved.....:( Is there a site I can place my code or program and get some help...Thank you
Reply With Quote
  #10 (permalink)  
Old November 18th, 2003, 07:18 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

What do you mean by "is there a site where I can place my code..."?

What about this forum? IMO this is the ideal location to post code so people can take a look at it, just like you have done before.

Please try to limit your code to the relevant portions. It's not much fun skimming hundreds of lines trying to discover a problem....

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
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
Calendar like calendar in AJAX in ASP.NET h@ckerz ASP.NET 2.0 Professional 0 February 19th, 2008 12:56 AM
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
VB.NET Calendar cyndie VB.NET 1 January 21st, 2005 07:05 AM
VS.Net Calendar KennethMungwira VS.NET 2002/2003 1 December 5th, 2003 05:27 AM
VB.net Calendar KennethMungwira VB.NET 2 November 13th, 2003 11:02 AM



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


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