Date/Time Problems

shootsnlad

Well-known member
Joined
Feb 14, 2002
Messages
46
I have an Access Database with some fields in it. 4 that are dates, and 1 is a time field. I have them setup as Date/Time fields in Access with the Format setting as Short Date for the date fields and Medium time for the time field. Now I have a Connection, Data Adapter, and Dataset in VB .NET setup to reference that table. I then have a form with all bunch of text boxes on it that are bound to the dataset and its fields. Now, when I create the dataset I just drag the table out of the Server Explorer to get the table definition. I change the Date/ Time type to Date in the definition for the date fields and I change the Date/Time to Time in the definition for the time field. My problem is the date text boxes still go with the long date (the date and time) and the time text box still display the long date, instead of just the time. It also saves to the database this way. Now I thought by having it defined in the dataset, as well as in Access, it should go with the short date, and time. Any ideas? Thanks.

shootsnlad
 
Hi

I found this code in 101 VB.NET

well frist Create a method like this

Code:
 Handle the Format event for the BirthDay  TextBox
    Protected Sub DateToString(ByVal sender As Object, _
    ByVal e As ConvertEventArgs)
        e.Value = CType(e.Value, DateTime).ToShortDateString
    End Sub

Then Create a second Method as follows

Code:
 Private Sub BindingFormats()
        Dim BirthdayDate As New Binding("Text", _
        DsMain1.Main, "BirthDay")

AddHandler BirthdayDate.Format, AddressOf DateToString

Me.txtBirthDay.DataBindings.Add(BirthdayDate)

End Sub

then onLoad Event of Application Form call the Method

Code:
 BindingFormats()


Dont Forget To Clear the Binding control at the Design Time

The one you had created


I hope it helps

bye
 
Back
Top