user1820339
user1820339

Reputation: 25

vb.net check if function don't return anything

I have a vb.net function is which I am doing some thing which is returning a gridview to send it in email.Problem is that when I call the function in email then email is sent even there is nothing returned by function. I don't to send blank email at all. I want to when function return nothing then it shouldn't send email. Here is My function

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

And I Call this in email function as a subject like this

email("[email protected]", "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), gridhtm(emaildata(GridView5, "chkStatusGM", 4)))

How can I do this that if emaildata(GridView5, "chkStatusGM", 4) returning nothing email shouldn't be sent?

Upvotes: 0

Views: 771

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460098

Probably the easiest is to check if the GridView contains GridViewRows with the Count property:

Dim grdEmail = emaildata(GridView5, "chkStatusGM", 4)
If grdEmail.Rows.Count > 0
    email("[email protected]", 
          "[Cheque Approval] GM Finance Reviewed (" & TreeView2.SelectedValue & ")" & subsmcnt(GridView5, "chkStatusGM", 4), 
          gridhtm(grdEmail))
End If 

Upvotes: 2

Related Questions