Format Date in Column Expression

L

leo.hart

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
 
E

Elton W

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
(e-mail address removed)
 
C

Cor Ligthert

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-fz_2c1f.asp

I hope this helps,

Cor
 
L

Leo

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top