I have a datagrid and when populated I would like to loop through the rows and
add the rows to a email below is how I setup the datagrids

  'Sets up the DGVInvItems DGV
    Public Sub setupRMAItems()
        DGVRMAItems.DataSource = GetRMAItems()
        DGVRMAItems.Columns("DetailID").Visible = False
        DGVRMAItems.Columns("PCode").Width = 150
        DGVRMAItems.Columns("PDescription").HeaderText = "Descripton"
        DGVRMAItems.Columns("PDescription").Width = 300
        DGVRMAItems.Columns("Qty").HeaderText = "Qty Invoiced"



    End Sub

    'Gets all lines for the selected invoice
    Public Function GetRMAItems() As DataView
        Dim SelectQry = "SELECT detailID,PCode,PDescription,Qty from TBLRMA_Detail WHERE RMANumber='" & Me.LBRMANumber.Text & "'"

        Dim ReturnItems As New DataSet
        Dim TableView As DataView
        Try
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = SelectQry
            SampleCommand.Connection = Connection
            SampleDataAdapter.SelectCommand = SampleCommand
            SampleDataAdapter.Fill(ReturnItems)
            TableView = ReturnItems.Tables(0).DefaultView
        Catch ex As Exception
            Throw ex
        End Try
        Return TableView
    End Function

here is how I send my email I would like help with the email body where I would like
all the datagrid rows to be shown.

        _NewCompEmailAddress = Me.txtemail.Text

        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New System.Net.Mail.MailMessage()
            SmtpServer.Credentials = New System.Net.NetworkCredential(_SMTPusername, _SMTPpassword)
            SmtpServer.Port = _SMTPport
            SmtpServer.Host = _SMTPmailserver

            mail = New System.Net.Mail.MailMessage()
            mail.From = New MailAddress("RMA@Leyland.co.uk", " RMA")
            mail.To.Add(_NewCompEmailAddress)
            mail.Subject = "New return authorisation case - " & Me.LBRMANumber.Text
            mail.Body = ?????? Datagridview rows...?????


            'return authorisation number

            SmtpServer.Send(mail)

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

any help would be greatfully received.

You might want to make TableView global or pass it to the sub doing to the email. Since you want the information in the body of the email, I would suggest putting the information into a formatted string, or converting it to html format.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.