View Single Post
  #8 (permalink)  
Old September 3rd, 2009, 05:20 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,652
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Kokoness showed you the answer in his post.

And WHY do you get the value out of the database *AS A STRING* if it's a DateTime value there???

Code:
foreach (DataRow r in ds.Tables[0].Rows)
{
    DateTime dt = r["First_Resurvey_Date"]; // do NOT convert it to string and then BACK to datetime!
    NotesLabel.Text = td.ToString("dd-MMM-yy"); 
    NotesLabel.Visible=true;
 }
...
Though why you would loop through all the rows and, in each row, set just the one label to the date, I don't get, at all.

I suspect that all you need is code to change the display of the value from the datatable *during* the binding to the datagrid. No?

But if you don't know how to do that, then maybe the right answer is to change your SQL query to get the date *AS A STRING* from Access.

Like this:
Code:
SELECT Right('0' & Day(yourfield),2) & '-' & MonthName(Month(yourfield),True) & '-' & Right(CStr(Year(yourfield)),2) AS formattedDate, ...
Reply With Quote