Results 1 to 11 of 11
  1. #1
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Database Connections (vb.net)

    I have a programme with a form in it with a text box linked to an Access database on it. (Following this tutorial)

    The text box displays a date field in a record set of a table in the database. The problem is the text box displays the date and time which I don

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Database Connections (vb.net)

    Assuming you're using a System.Windows.Forms textbox, you can do this in the Load event of the form:

    Text.Format("dd-mm-yyyy", Me.Text1)

    Where Text1 is the name of the textbox, and dd-mm-yyyy represents the date format string.
    Charlotte

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Isn't that String.Format("mm-dd-yyyy", Me.Text1.Text)

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Database Connections (vb.net)

    No, I wasn't formatting a string, I was applying a date format to the text property of the textbox control.
    Charlotte

  5. #5
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Whoops - right you are... <img src=/S/newbrain.gif border=0 alt=newbrain width=21 height=22>

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Database Connections (vb.net)

    <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> Isn't .Net fun, Mark? There are so many ways to do things and so many things you can do that they all start to look alike and they all run together after a while. <img src=/S/nuts.gif border=0 alt=nuts width=15 height=15>
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Tried that, thanks, didn't make any difference though!

    The text box is the only one on the form that is connected to the database and the only one with the odd format. The field that it is connected to is in an Access database that has 8 records in it, all of which contain a date only, no time information. When these dates display on the VB form they all display the date correctly but have 00:00:00 tacked on the end after the date.

    Any other suggestions gratefully received. Or any other way of displaying only the date in another text box and hide the one that's connected to the database.

    I have to say though it is quite encouraging as a beginner to see that the experts don't always get 100%!!!

    Regards

    Graeme

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Database Connections (vb.net)

    Just who are you calling an expert? [yikes} I'm new to VS.Net myself, and we don't use the System.Windows.Forms controls, so I didn't fully test the suggestion. Here's an alternative that might work for you:

    Text1.Text = Date.Parse(Text1.Value.ToString("dd-mm-yyyy"))

    Oh, and the reason for the "00:00:00" is because all dates have a time component. That happens to be midnight, the default.
    Charlotte

  9. #9
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Thanks again for coming back.

    I got 'value' is not a member of 'System.Windows.Forms.Textbox'.

    And indeed it does not appear in the list after typing Text1.

    The plot thickens!

    Graeme

  10. #10
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Try this article. An example is provided near the bottom of the page.

    Hope this helps...

  11. #11
    2 Star Lounger
    Join Date
    Sep 2007
    Location
    Chatham, Kent, England
    Posts
    214
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Database Connections (vb.net)

    Mark

    Great article. I got quite excited on reading the bit towards the end:

    <The problem came when I was trying to bind a datetime field from SqlServer with a text property of the textbox control. Since, SqlServer stores stores the date in "MM/dd/yyyy hh:mm:ss" format, so the textbox would display the time along with the date. No matter how much I tried to remove the time portion in the display, I could not. Then, I came across the events of the Binding class and the solution using events was very easy and elegant.>

    This is what we want! I'll work through the solution and post back.

    Thanks again.

    Regards

    Graeme

Posting Permissions

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