Results 1 to 2 of 2

Thread: [2.0]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    [2.0]

    why this code doesnt work?

    Code:
    DateTime1.Text = datetime.now

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0]

    What does the error message say? Something like "cannot convert DateTime to String"? The Text property of any control expects a String object. The DateTime.Now property returns a DateTime object. You cannot stick a square peg in a round hole.

    You could convert the DateTime object to a String by calling one of its methods, like ToString, but I'm guessing that DateTime1 refers to a DateTimePicker control. If that's the case then you should never be setting its Text property. You should be setting its Value property:
    C# Code:
    1. DateTime1.Value = DateTime.Now;
    The Value property is type DateTime.

    You should always read the documentation for the classes you're using, particularly if they don't work the way you expect. If you'd done that you probably could have solved this on your own.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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