This is a 3 program issue: first I have an ASP.NET app. which saves data to SQL and has an export screen to save to Excel.
Is there anything I can do with this script to make the column be a date when exported using the .NET below. It shows as text looking like a date 5/12/13 or a 5 digit number such as 44987 (not the real date) in either example following.
The date column is currently this > DateAwarded(date, null)
if I use this SQL it changes it to a date like 5/12/13 but then in Excel it text and the user wants a date.
The user does not want to have to reformat every export they do while in Excel.
Also here is the ASP.NET 4.0 code
Is there anything I can do with this script to make the column be a date when exported using the .NET below. It shows as text looking like a date 5/12/13 or a 5 digit number such as 44987 (not the real date) in either example following.
The date column is currently this > DateAwarded(date, null)
Code:
SELECT CommonName, CONVERT(int, EmployeeEpriseID, 101) AS EmployeeEpriseID, Location,VPName, Nominator, ReportToManager, Report1, Report2, Report3, AwardType, [highlight #FCE94F]CONVERT(date, DateAwarded, 101) AS DateAwarded[/highlight], Event, NominationSummary FROM Recognition Where year(DateAwarded) = 2013 AND VPName = 'fred flintstone' And ePrizeID = '12345678' ORDER BY UniqueID DESC
-- If I change the SQL above to this, it makes a real date but its text in Excel.
[highlight #FCE94F]CONVERT (nvarchar(12), DateAwarded, 101) AS DateAwarded[/highlight]
The user does not want to have to reformat every export they do while in Excel.
Also here is the ASP.NET 4.0 code
Code:
ws.Cells("A1").LoadFromDataTable(tbl, True)
'Write it back to the client
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + ExcelFilename + ".xlsx")
HttpContext.Current.Response.BinaryWrite(pck.GetAsByteArray())
HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()