views:

81

answers:

2

I have a process which grabs the birthdate and from a data table and display them in a masked text box for viewing and editing

However when pushing the data into the textbox any preceding zeros get removed

For example 05/05/2005 would display as 55/20/05__

The masked Text box is set up as 00/00/0000

The line which assigns the code is:

MaskedTextBox.Text = Format(DataTable(0)("DOB"), “MM/dd/yyyy”).ToString

To date I have tried the following:

  • Delete and re-add the control
  • Copy masked textbox from another form in the same program
  • Above Masked textbox grabs the same information from the same database table and is formatted exactly the same and it works
  • Tried various different formats including no format all with the same result

Does anyone have any other suggestions?

A: 

Try converting the Datatable data to date and back:

MaskedTextBox.Text = Date.Parse(DataTable(0)("DOB")).ToString("MM/dd/yyyy")

My guess is that either the database is sending the date in a format you don't expect, you changed the control's Culture (under Behaivior properties), or that you changed the way your computer shows dates and thus changed its culture. However I try I can't replicate the problem with my culture settings.

Wilhelm
Got this 84/19/69_1 as a result
Sean
+1  A: 

I think I am going to ave to put this in "Mysteries of the Unexplained " box.

At the advice of another developer I manually recreated the form, re-added all the controls and it now works fine (copy and pasting all the controls from one form to another caused the issue to come with it).

I really don't know how to even recreate the issue must be something in the forms design level code???

Anyway thanks for all the assistance from everyone.

Sean