|
 |
ado_dotnet thread: datetime binding
Message #1 by bianouni@h... on Wed, 19 Feb 2003 11:58:10
|
|
I am using c # windows forms and binding controls to DB fields.
I have problem with datetime fields. The problem is that when binding a
datetime field to textbox then it shows the value with date and time
format.
I want to show it with date format only (dd/MM/yyyy for example)
Can any one help?
Thanks
Message #2 by "Duncan" <duncan.faulkner1@b...> on Wed, 19 Feb 2003 12:48:58 -0000
|
|
Hi
I know these are for VB.net,
Protected Sub DateToString(ByVal sender As Object, ByVal e As
ConvertEventArgs)
'you could use either of the following to convert to the proper
date format:
'e.Value = ctype(e.Value,DateTime).ToString("d")
e.Value = CType(e.Value, DateTime).ToShortDateString
End Sub
Protected Sub StringToDate(ByVal sender As Object, ByVal e As
ConvertEventArgs)
Try
e.Value = CDate(e.Value)
Catch exp As Exception
MessageBox.Show("Data entry error: " & exp.Message, Me.Text,
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
To call these protected subs,
Dim DateBinding As New Binding("Text", sqlDataView,
"FieldName")
AddHandler DateBinding.Format, AddressOf DateToString
AddHandler DateBinding.Parse, AddressOf StringToDate
txtDate.DataBindings.Add(DateBinding)
HTH
Duncan
-->-----Original Message-----
-->From: bianouni@h... [mailto:bianouni@h...]
-->Sent: 19 February 2003 11:58
-->To: ADO.NET
-->Subject: [ado_dotnet] datetime binding
-->
-->
-->I am using c # windows forms and binding controls to DB
-->fields. I have problem with datetime fields. The problem is
-->that when binding a
-->datetime field to textbox then it shows the value with date and time
-->format.
-->I want to show it with date format only (dd/MM/yyyy for
-->example) Can any one help? Thanks === Fast Track ADO.NET
-->with C# is a concise introduction to the concepts,
-->techniques, and libraries that you will need in order to
-->start using ADO.NET in your applications. The book covers
-->DataSets and Typed DataSets, accessing data using
-->DataReaders and DataAdaptors, the close relationship between
-->ADO.NET and XML, how and where to use ADO.NET in your
-->enterprise applications, and how to use Web Services and
-->ADO.NET to easily pass data between applications.
-->http://www.wrox.com/books/1861007604.htm
-->---
-->Change your
-->mail options at
-->
-->
-->
|
|
 |