我有一个vb.net函数,我正在做一些事情,它返回一个gridview,在email中发送它。问题是,当我在电子邮件中调用该函数时,即使函数没有返回任何内容,也会发送电子邮件。我根本不发送空白电子邮件。我希望当函数返回什么,然后它不应该发送电子邮件。这是我的功能
Public Function emaildata(ByVal grdv As GridView, ByVal chk As String, ByVal celpos As Integer) As GridView
Dim comm As OleDbCommand = New OleDbCommand()
Dim bpv As String = ""
Dim gv As New GridView
For Each gvrow As GridViewRow In grdv.Rows
Try
Dim rdobtn As RadioButtonList = CType(gvrow.FindControl(chk), RadioButtonList)
If rdobtn.SelectedValue.Equals("5") Or rdobtn.SelectedValue.Equals("1") Or rdobtn.SelectedValue.Equals("6") Or rdobtn.SelectedValue.Equals("4") Or rdobtn.SelectedValue.Equals("2") Then
If bpv <> "" Then
bpv += ","
End If
bpv += gvrow.Cells(celpos).Text
comm.CommandText = "SELECT row_number() over(order by rownum) Sr, to_char(chq_num) Cheque#,to_char(bpv_amt,'9,999,999,999') Amount,vch_nar Narration,bnf_nam PartyName,acc_des Bank from CHECK_DATA where bpv_num in(" & bpv.ToString() & ") and BPV_DTE=to_date('" & TreeView2.SelectedValue & "') union all SELECT null,'Total :',to_char(sum(bpv_amt),'9,999,999,999') Amount,null,null,null from CHECK_DATA where bpv_num in(" & bpv.ToString() & ") and BPV_DTE=to_date('" & TreeView2.SelectedValue & "')"
comm.CommandType = CommandType.Text
comm.Connection = con
Dim da As New OleDbDataAdapter(comm)
Dim ds As New DataSet
da.Fill(ds)
gv.DataSource = ds
gv.DataBind()
End If
Catch ex As Exception
Response.Write("There is Problem In Cheque Approval System Please Contact With IT")
End Try
Next
Return gv
End Function
我将此电子邮件功能称为此主题
email("malik.adeel@shakarganj.com.pk", "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), gridhtm(emaildata(GridView5, "chkStatusGM", 4)))
如果emaildata(GridView5, "chkStatusGM", 4)
不返回任何电子邮件,我该怎么办呢?
答案 0 :(得分:2)
最简单的方法是检查GridView
是否包含GridViewRows
Count
属性:
Dim grdEmail = emaildata(GridView5, "chkStatusGM", 4)
If grdEmail.Rows.Count > 0
email("malik.adeel@shakarganj.com.pk",
"[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4),
gridhtm(grdEmail))
End If