我有一个由Windows调度程序运行的程序...每次运行时,它都会在我们的数据库上运行查询,抓取信息然后通过电子邮件发送它。这一切都像宣传的那样工作,但我似乎无法找到如何格式化日期和美元金额。我的C#代码是:
Imports System.Net.Mail
Imports System.Linq
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Me.Paid_Out_TbTableAdapter.Fill(Me.DataSet.Paid_Out_Tb)
Dim payouts = _
<html>
<body>
<table border="1">
<tr><th>Store #</th><th>Date</th><th>Amount</th><th>User</th><th>Comment</th></tr>
<%= From paidOut In Me.DataSet.Paid_Out_Tb.AsEnumerable _
Select <tr><td><%= paidOut.Store_Id %></td>
<td><%= paidOut.Paid_Out_Datetime %></td>
<td><%= paidOut.Paid_Out_Amount %></td>
<td><%= paidOut.Update_UserName %></td>
<td><%= paidOut.Paid_Out_Comment %></td></tr> %>
</table>
</body>
</html>
SmtpServer.Credentials = New _
Net.NetworkCredential("****", "****")
SmtpServer.Port = 25
SmtpServer.Host = "10.0.*.*"
mail = New MailMessage()
mail.From = New MailAddress("***@***.com")
mail.To.Add("***@***.com")
'mail.CC.Add("***@**.com")
mail.Subject = "Paid Out Report for 1929"
mail.IsBodyHtml = True
mail.Body = payouts.ToString()
SmtpServer.Send(mail)
'MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Me.Close()
End Sub
我的查询是:
SELECT Store_Id, Paid_Out_Amount, Paid_Out_Comment, Paid_Out_Datetime, Update_UserName, Till_Number
FROM Paid_Out_Tb
WHERE (Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)) AND (Paid_Out_Datetime < DATEADD(day, DATEDIFF(day, 0,
GETDATE()), 0)) AND (Paid_Out_Amount > 20) OR
(Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)) AND (Paid_Out_Datetime < DATEADD(day, DATEDIFF(day, 0,
GETDATE()), 0)) AND (Paid_Out_Comment LIKE N'%' + 'Filter' + '%')
最后输出是:
Store # Date Amount User Comment
1929 2012-07-22T12:18:23.33 29.0000 KAG PIZZA AND TIP FOR STORE
正如你所看到的那样,日期是长形式的...我只是喜欢7/22/12和我想要的金额29.00美元......如何正确格式化输出?
答案 0 :(得分:1)
您应该能够使用.ToString()
,传入正确的格式字符串,以获得所需的格式。您可能需要事先进行一些转换,具体取决于为DataSet指定的类型(如果有):
<td><%= Convert.ToDateTime(paidOut.Paid_Out_Datetime).ToString("M/d/yy") %></td>
<td><%= Convert.ToDecimal(paidOut.Paid_Out_Amount).ToString("0.00") %></td>