Results 1 to 2 of 2

Thread: Input String was not in a correct format

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    175

    Input String was not in a correct format

    I have a label on a page load event that I'm trying to display the current date and time in the long format and have this line of code:

    Code:
            TimeDateLabel.Text = String.Format("Today's date is {D}", DateTime.Now)
    but when I load the page I am presented with the error that the Input String was not in a correct format. I thought that that format was correct. Can anyone tell me what is wrong with my format?

    Thank you

    Doug

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

    Re: Input String was not in a correct format

    When you use String.Format, all place-holders must have a number that refers to the index of a parameter. The first parameter is number 0, the second is number 1, etc. If you then want to provide a format string as well, you follow the number with a colon and then the format string. Your code should be:
    Code:
    TimeDateLabel.Text = String.Format("Today's date is {0:D}", DateTime.Now)
    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