Column DefaultValue (Very easy question)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nev
    Contributor
    • Oct 2007
    • 251

    Column DefaultValue (Very easy question)

    I use VB 2005 Pro v8.0.50727.42

    I use datadesigner to manage my dataset. In my form, I dragged a datagridview of one of my tables. It has a date column. In the property pane for the date column, there is a defaultvalue which is set to <dbnull>. How do I set it so that the defaultvalue is the current date?

    I tried changing <dbnull> to...
    1. <Date> 'does not do the job.
    2. <Date(Now())> 'no luck
    3. <Now()> 'still nothing

    What should I put in the defaultvalue property so that the column's defaultvalue will be the date today? Or is this possible?
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .NET Forum.

    Comment

    • nev
      Contributor
      • Oct 2007
      • 251

      #3
      Originally posted by nev
      I use VB 2005 Pro v8.0.50727.42

      I use datadesigner to manage my dataset. In my form, I dragged a datagridview of one of my tables. It has a date column. In the property pane for the date column, there is a defaultvalue which is set to <dbnull>. How do I set it so that the defaultvalue is the current date?

      I tried changing <dbnull> to...
      1. <Date> 'does not do the job.
      2. <Date(Now())> 'no luck
      3. <Now()> 'still nothing

      What should I put in the defaultvalue property so that the column's defaultvalue will be the date today? Or is this possible?
      Does anyone know how to do this? In design-time?

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        Originally posted by nev
        Does anyone know how to do this? In design-time?
        DateTime.Now is the .Net way of getting the current date.

        So guess you should try that.
        I have upto now havent had to set default values to non numeric columns...so at the moment im just guessing

        Comment

        • nev
          Contributor
          • Oct 2007
          • 251

          #5
          My column is a stringtype. I tried to place DateTime.Now in the defaultvalue property @ design-time. When I run the program and place my cursor in the newrow of the datagridview, it displays "DateTime.N ow".

          Comment

          • nev
            Contributor
            • Oct 2007
            • 251

            #6
            Originally posted by nev
            My column is a stringtype. I tried to place DateTime.Now in the defaultvalue property @ design-time. When I run the program and place my cursor in the newrow of the datagridview, it displays "DateTime.N ow".
            Update!

            I changed the column's datatype in the mysql database as well as in the datadesigner in vb 2005 into datetime. This time when I place datetime.now in the defaultvalue property, it errors 'Property value is invalid. The string was not recognized as a valid DateTime.'

            Comment

            • Shashi Sadasivan
              Recognized Expert Top Contributor
              • Aug 2007
              • 1435

              #7
              Originally posted by nev
              Update!

              I changed the column's datatype in the mysql database as well as in the datadesigner in vb 2005 into datetime. This time when I place datetime.now in the defaultvalue property, it errors 'Property value is invalid. The string was not recognized as a valid DateTime.'
              is this a windows form based application or asp .net?

              I have a work around fix for this for windows forms.

              Comment

              • nev
                Contributor
                • Oct 2007
                • 251

                #8
                Originally posted by Shashi Sadasivan
                is this a windows form based application or asp .net?

                I have a work around fix for this for windows forms.
                It is a winform based app. I can do it through code. But I wanna learn how to do it @ design-time.

                Through code:
                dataset.table.c olumn.defaultva lue = datetime.now.to shortdatestring

                Through property pane @ design-time:
                defaultvalue | ???

                Comment

                Working...