Results 1 to 14 of 14

Thread: Datetimpicker

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Datetimpicker

    Hi there!
    Pls help me with my code
    i want to save the values from these code wriiten below,but the value did not incremented after saving..please help me

    thank you!
    vb.net Code:
    1. Dim startDate = Date.Today
    2.         Dim endDate = DateTimePicker1.Value.Date
    3.  
    4.         Do While startDate <= endDate
    5.             MsgBox(startDate.ToShortDateString)
    6.             startDate = startDate.AddMonths(1)
    7.         Loop
    8.  
    9.         strSQL = "Insert into Lenders_CollectDate (TransactionID,DateCollect_1,dateCollect_2,DateCollect_3) values ('" & txtTransacID.Text & "','" & startDate.ToShortDateString & "','" & startDate.ToShortDateString & "','" & startDate.ToShortDateString & "')"
    10.         SQLalter_Table(strSQL)
    11.         MsgBox("Ok")

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datetimpicker

    Perhaps moving your INSERT inside the loop would be more along the lines of what you are after.

    As it is, it is only inserting one record using the last date calcuated.

  3. #3
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datetimpicker

    Seems the code responsible for the update in regards to SQLalter_Table(strSQL) which you have not shown is where the problem is. Unless you show this code all that can be done is guess so best to show your code.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Datetimpicker

    what are the datatypes of:

    TransactionID
    DateCollect_1
    dateCollect_2
    DateCollect_3

    ???

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Datetimpicker

    sorry for incomplete information..to make it clear

    date Today is 09/08/2011
    selected date from datetimepicker is 01/08/2012

    for example I want to save the value of
    09/09/2011-Firstmonth
    10/09/2011-SecondMonth
    11/09/2011-thirdMonth
    12/09/2011-FourthMonth
    01/09/2012-FifthMonth
    until it reached the selected value from datetimpicker.

    Pls.Help me..

    Thank you very much!

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Datetimpicker

    What does SQLalter_Table(strSQL) do ???

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Datetimpicker

    I just want to save the incremented months to my database...

    using (do while) but it gives me values that i'm selected not the incremented values...

    pls help me...

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Datetimpicker

    SqlAlterTable- that is my function to save and update values on my database..

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Datetimpicker

    your call to the routine that inserts the values into the database is outside of the loop... move it into the loop and it just might work. Call me crazy, but it just might work.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: Datetimpicker

    Techgnome has already provided a solution to the sql insert problem. If the problem is about adding months to the target date specified in the Datetimepicker then, the following example could possibly help you.

    vb.net Code:
    1. Dim startDate = Date.Today
    2. Dim endDate = DateTimePicker1.Value.Date
    3.  
    4. Do While endDate = DateTimePicker1.Value.Date
    5.    If startDate >= endDate Then Exit Do
    6.    startDate = startDate.AddMonths(1)
    7.    MsgBox(startDate.ToShortDateString)
    8. Loop

  11. #11

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Datetimpicker

    Please Help!

    How to get Semi-Annual(or every 6 months) using Datetimepicker?

  12. #12
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: Datetimpicker

    Quote Originally Posted by ralphzxess View Post
    Please Help!

    How to get Semi-Annual(or every 6 months) using Datetimepicker?
    It sounds like you want to save all the 6 different dates on a single click. Do you have different fields like First_Month, Second_Month etc ? Or trying to insert 6 rows all at once ? The exact problem is still unknown.
    .

  13. #13

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    12

    Re: Datetimpicker

    To make it clear...

    I have a 2 datetimpicker,

    This is my code



    DateDIff(DateInterval.Year,Datetimpicker1,Datetimpicker2)/2


    how can I get the dateinterval of Semi-Annual?

  14. #14
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: Datetimpicker

    try this:

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim SemiAnnual As Date = DateTimePicker2.Value
    4.         Dim MyDate As Date
    5.         Dim firstDate, msg As String
    6.         Dim secondDate As Date
    7.  
    8.         MyDate = SemiAnnual.AddMonths(6)
    9.         DateTimePicker2.Value = MyDate
    10.  
    11.         firstDate = DateTimePicker1.Value
    12.         secondDate = DateTimePicker2.Value
    13.         msg = "Months from today: " & DateDiff(DateInterval.Month, Now, secondDate)
    14.         MsgBox(msg)
    15.  
    16. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width