我有一个通过调度程序自动启动 Windows 的程序。它所做的是运行查询,然后通过电子邮件发送查询结果。这一切都有效。我们有 10 个位置,因此我将对其进行编辑,以便它发送 5 封不同的电子邮件...我遇到的问题是如何检查多个 tableadapter 是否具有空值。你会看到我让它检查“Paid_Out_TB”以查看它是否有 0 行......如果有 0 行程序关闭。我想做的是检查它是否有 0 行。如果是,请在电子邮件中报告表格数据,然后检查下一个表格适配器,是否包含行?如果是这样,也要报告...在没有数据的情况下遗漏任何表格...问题是...如果没有数据,我需要告诉它做某事...有什么建议吗?
Imports System.Net.Mail
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
'TODO: This line of code loads data into the 'DataSet.Paid_Out_Tb' table. You can move, or remove it, as needed.
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Me.Paid_Out_TbTableAdapter.Fill(Me.DataSet.Paid_Out_Tb)
Me.DataTable1TableAdapter.Fill(Me.DataSet.DataTable1)
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><%= Convert.ToDateTime(paidOut.Paid_Out_Datetime).ToString("M/d/yy") %>
</td><td><%= "$" & paidOut.Paid_Out_Amount.ToString("0.00") %></td>
<td><%= paidOut.Update_UserName %></td>
<td><%= paidOut.Paid_Out_Comment %></td></tr> %>
</table>
</body>
</html>
Dim Payouts453 = _
<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.DataTable1.AsEnumerable _
Select <tr><td><%= paidOut.Store_Id %></td>
<td><%= Convert.ToDateTime(paidOut.Paid_Out_Datetime).ToString("M/d/yy") %>
</td><td><%= "$" & paidOut.Paid_Out_Amount.ToString("0.00") %></td>
<td><%= paidOut.Update_UserName %></td>
<td><%= paidOut.Paid_Out_Comment %></td></tr> %>
</table>
</body>
</html>
If (Me.DataSet.Paid_Out_Tb.Count = 0) Then 'This cheks to see if the dataset is Null. We do not want to email if the set is Null
Me.Close()
Else
SmtpServer.Credentials = New _
Net.NetworkCredential("****", "****") 'Assign the network credentials
SmtpServer.Port = 25 'Assign the SMTP Port
SmtpServer.Host = "10.0.*.**" 'Assign the Server IP
mail = New MailMessage() 'Starts a mail message
mail.From = New MailAddress("*@**.com") 'Sets the "FROM" address
mail.To.Add("**@**.com") 'Sets the "To" address
'mail.CC.Add("**@**.com") 'set this if you would like to CC
mail.Subject = "Paid Out Report for 1929"
mail.IsBodyHtml = True
mail.Body = payouts.ToString() & Payouts453.ToString() 'this is to add another chart You would use a seperate dataset obviously
SmtpServer.Send(mail)
'MsgBox("mail send")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Me.Close() 'Closes the program when it's finished.
End Sub