Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 it's 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

Posted

Hi

 

I found this code in 101 VB.NET

 

well frist Create a method like this

 


' 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

 


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

 


BindingFormats()

 

 

Don't Forget To Clear the Binding control at the Design Time

 

The one you had created

 

 

I hope it helps

 

bye

Gary Says: To be a good programmer, you must be good at debugging

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...