0

我有一个由 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 美元的金额……如何正确格式化输出?

4

1 回答 1

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>
于 2012-07-30T15:31:55.267 回答