Masking the time of datetime

robbycraig

Member
Joined
Mar 2, 2006
Messages
7
Programming Experience
1-3
I have a windows form bound to a dataset. That is filled by an sqldataadapter which gets its data from a table in sql server 2000.
In my table on sql server I have a date column, when I view the data in sql server it only displays the date not the time which I know is also stored there as 00:00:00 this is the behavior I want.

Once I have the data in my data set I have a text box bound to this column but when I view my form it displays the date as well as the time part. I can get rid of this by using the following code,

VB.NET:
[COLOR=black]me.textDate.text = DateValue(me.textDate.text)[/COLOR]

the problem with this is as I navigate through my record set it thinks that I have made changes to the dataset so the user is asked to save changes when they exit when they haven’t made any.

Can anyone please offer me another solution to this? any help will be much appreciated
 
look into ToShortDateString

Use some form of ToShortDateString

dim dt as dt As DateTime = DateTime.Now
textDate.text = dt.ToShortDateString
 
Unsolved

This doesn't solve my problem as any changes to the date that appears in the cell makes the dataset think it has changes, when it doesn't.
 
Here's what you need.

VB.NET:
Dim WithEvents MyBinding as DataBinding
MyBinding = New Binding("Text", your Datatable,Thecolumn)
YourTextBox.Bindings.add(MyBinding)

Then because we've declared our binding object withevents it can now raise events. so select it and click on 'Format' to open up the event handler. Then something like this...

VB.NET:
e.value = Format(e.value,"dd/MM/yyyy")

Job Done.
 
Back
Top