datetimepicker dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clamara

    datetimepicker dataset

    When adding a new record from my form, I pre-set my DateTimePicker' s value to
    System.DateTime .Today
    Since the "Today" value is used most of the time, the user doesn't need to
    select a date from the DateTimePicker, since the default is shown. My problem
    is, if the user does not choose a value from the DateTimePicker (because
    using the default is good enough), then during database update, the date
    value is not saved to the database; while if user choose another value other
    then the default, the value can be saved to the database successfully. Is
    there a way to ensure the default value can be saved to the database?
  • Earl

    #2
    Re: datetimepicker dataset

    If Then

    Else

    End If

    "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
    news:C6D1994E-E021-4FC8-925B-F3816A26319F@mi crosoft.com...[color=blue]
    > When adding a new record from my form, I pre-set my DateTimePicker' s value
    > to
    > System.DateTime .Today
    > Since the "Today" value is used most of the time, the user doesn't need to
    > select a date from the DateTimePicker, since the default is shown. My
    > problem
    > is, if the user does not choose a value from the DateTimePicker (because
    > using the default is good enough), then during database update, the date
    > value is not saved to the database; while if user choose another value
    > other
    > then the default, the value can be saved to the database successfully. Is
    > there a way to ensure the default value can be saved to the database?[/color]


    Comment

    • Clamara

      #3
      Re: datetimepicker dataset

      it's a joke???

      "Earl" wrote:
      [color=blue]
      > If Then
      >
      > Else
      >
      > End If
      >
      > "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
      > news:C6D1994E-E021-4FC8-925B-F3816A26319F@mi crosoft.com...[color=green]
      > > When adding a new record from my form, I pre-set my DateTimePicker' s value
      > > to
      > > System.DateTime .Today
      > > Since the "Today" value is used most of the time, the user doesn't need to
      > > select a date from the DateTimePicker, since the default is shown. My
      > > problem
      > > is, if the user does not choose a value from the DateTimePicker (because
      > > using the default is good enough), then during database update, the date
      > > value is not saved to the database; while if user choose another value
      > > other
      > > then the default, the value can be saved to the database successfully. Is
      > > there a way to ensure the default value can be saved to the database?[/color]
      >
      >
      >[/color]

      Comment

      • Earl

        #4
        Re: datetimepicker dataset

        If ...... Then

        yourDate = DateTimePicker1 .Value.Date

        Else

        yourDate = Now.Date

        End If



        "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
        news:08A44DDA-009D-403B-AFA1-7FE346E7DD52@mi crosoft.com...[color=blue]
        > it's a joke???
        >
        > "Earl" wrote:
        >[color=green]
        >> If Then
        >>
        >> Else
        >>
        >> End If
        >>
        >> "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
        >> news:C6D1994E-E021-4FC8-925B-F3816A26319F@mi crosoft.com...[color=darkred]
        >> > When adding a new record from my form, I pre-set my DateTimePicker' s
        >> > value
        >> > to
        >> > System.DateTime .Today
        >> > Since the "Today" value is used most of the time, the user doesn't need
        >> > to
        >> > select a date from the DateTimePicker, since the default is shown. My
        >> > problem
        >> > is, if the user does not choose a value from the DateTimePicker
        >> > (because
        >> > using the default is good enough), then during database update, the
        >> > date
        >> > value is not saved to the database; while if user choose another value
        >> > other
        >> > then the default, the value can be saved to the database successfully.
        >> > Is
        >> > there a way to ensure the default value can be saved to the database?[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        • Clamara

          #5
          Re: datetimepicker dataset

          I think you misunderstand me...

          PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS

          try this with vb.net 2003

          create with the dataform wizard a form that bind to a simple sql table with
          productID and dateofproduct (datetime and not nullable).
          If you show the form the load event put as dateofproduct default the today's
          date but if you try to update the dataset without touch the datetimepicker
          control the dataset reject to update cause the datetimepicker value is null.
          While if I touch the datetimepicker control and i choose a date the update
          works.

          My problem
          is, if the user does not choose a value from the DateTimePicker (because
          using the default is good enough) the update doesn't works.

          I haved try to set datetimepicker. value = now() during the load event but it
          doesn't work.

          Comment

          • Earl

            #6
            Re: datetimepicker dataset

            I think I understand you. You need to pass a non-null date value to the
            dataset when the datetimepicker has not been selected. This is indeed the
            way I would do it (and have done it).

            But without any code, there is much that all of us would be speculating
            upon. How are the datetimepicker values being passed to the dataset? What
            causes the the update to be applied to the backend database?

            Fundamentally, the answer is the same however you are coding it -- you
            either need to pass a non-null Date value (if Today.Date is acceptable), or
            you need to protect for null being passed (another way of doing it).

            To get a better answer, you will have to show the code snippet.

            "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
            news:0166CF4A-20EC-418C-981F-DB136C019441@mi crosoft.com...[color=blue]
            >I think you misunderstand me...
            >
            > PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS PLEASE TRY THIS
            >
            > try this with vb.net 2003
            >
            > create with the dataform wizard a form that bind to a simple sql table
            > with
            > productID and dateofproduct (datetime and not nullable).
            > If you show the form the load event put as dateofproduct default the
            > today's
            > date but if you try to update the dataset without touch the datetimepicker
            > control the dataset reject to update cause the datetimepicker value is
            > null.
            > While if I touch the datetimepicker control and i choose a date the update
            > works.
            >
            > My problem
            > is, if the user does not choose a value from the DateTimePicker (because
            > using the default is good enough) the update doesn't works.
            >
            > I haved try to set datetimepicker. value = now() during the load event but
            > it
            > doesn't work.[/color]


            Comment

            • Ken Tucker [MVP]

              #7
              Re: datetimepicker dataset

              Hi,



              Ken
              ----------------
              "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
              news:C6D1994E-E021-4FC8-925B-F3816A26319F@mi crosoft.com...
              When adding a new record from my form, I pre-set my DateTimePicker' s value
              to
              System.DateTime .Today
              Since the "Today" value is used most of the time, the user doesn't need to
              select a date from the DateTimePicker, since the default is shown. My
              problem
              is, if the user does not choose a value from the DateTimePicker (because
              using the default is good enough), then during database update, the date
              value is not saved to the database; while if user choose another value other
              then the default, the value can be saved to the database successfully. Is
              there a way to ensure the default value can be saved to the database?


              Comment

              • Clamara

                #8
                Re: datetimepicker dataset

                thank you ken, I have try the link that you give me....from this i search for
                other code and i find this link


                this one it's very cool

                thank you

                "Ken Tucker [MVP]" wrote:
                [color=blue]
                > Hi,
                >
                > http://www.windowsforms.net/Forums/S...=41&PostID=948
                >
                > Ken
                > ----------------
                > "Clamara" <Clamara@discus sions.microsoft .com> wrote in message
                > news:C6D1994E-E021-4FC8-925B-F3816A26319F@mi crosoft.com...
                > When adding a new record from my form, I pre-set my DateTimePicker' s value
                > to
                > System.DateTime .Today
                > Since the "Today" value is used most of the time, the user doesn't need to
                > select a date from the DateTimePicker, since the default is shown. My
                > problem
                > is, if the user does not choose a value from the DateTimePicker (because
                > using the default is good enough), then during database update, the date
                > value is not saved to the database; while if user choose another value other
                > then the default, the value can be saved to the database successfully. Is
                > there a way to ensure the default value can be saved to the database?
                >
                >
                >[/color]

                Comment

                Working...