Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

Format Date in Column Expression

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
leo.hart@fmr.com - 15 May 2005 14:47 GMT
Hello,

Let's say I have a typed DataTable called "MyDataTable" and it has the
following columns:

ID: Integer
Name: String
StartDate: Date
DisplayName: String

ID, Name and StartDate are generally filled through an ADO.NET
DataAdapter call, but DisplayName should be based on expression.
MyDataTable will be used to populate a ComboBox, where ID is the
ValueMember and DisplayName is the DisplayMember.

So what I'm trying to do is create an Expression on my DisplayName
column:

MyDataTable.columnDisplayName.Expression = "ID + ' - ' + Name + ' - ' +
StartDate"

This works and does not throw an error, however it displays the
StartDate section in the wrong format.  I would like to display
StartDate in the format of MM/dd/yyyy.  Is there any way to do this?
Can I use methods like StartDate.ToString('MM/dd/yyyy') in a column
expression?  I tried but it seems to throw an error.

Thanks,
Leo Hart
Elton W - 15 May 2005 22:12 GMT
Hi Leo,

I just guess that the reason the causes date formatting
problem maybe is some value of date in datatable is
DbNull.

HTH

Elton Wang
elton_wang@hotmail.com
Leo - 16 May 2005 02:27 GMT
So this SHOULD Work then?
Cor Ligthert - 16 May 2005 08:42 GMT
Leo,

> So this SHOULD Work then?

AFAIK is the answer on this "No" the "expression" is strange enough a
program language it self, which has nothing to do with the semantic of any
other Net code. Probably is the base for that SQL, which is in my opinion
very much based on local USA standards.

However maybe can you do something by creating first 3 columns in your SQL
Select.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_fa-f
z_2c1f.asp


I hope this helps,

Cor
Leo - 17 May 2005 11:30 GMT
Yeah, I'd rather not assemble the three columns in my SQL as that
starts looking like presentation logic in the data tier, to me anyway,
and I want to try to avoid that.  But that may be what I have to do.

Thanks for your help!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.