Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

row count on table header running sql

$
0
0
Hi I am using the following code to execute a query and have the result sent to the email in html format. But in the email i am automatically receiving a row count on top of the table. How to either eliminate that row count or move to the bottom of the table in the email body? Any help please?

--------------------------------------------
# Setup SQL

$SqlName = "TRANS"
$SqlCmd =  "select * from boo"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = TSNUbx237-49; Database = TSN; Integrated Security = True"

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlCommand
$SqlCmd.Connection = $SqlConnection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd

$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)

[string]$Body = "<H3>"+$SqlName+"</H3>"

## Set dataset into html email format
[string]$EmailBody = $DataSet.Tables | Select-Object -Expand Rows |
select * -ExcludeProperty RowError, RowState, HasErrors, Name, Table, ItemArray |
ConvertTo-HTML -Body $Body

## Email
$Server = "smtp.TSN.srv"
$MTA = New-Object Net.Mail.SMTPclient($Server)
$Msg = New-Object Net.Mail.MailMessage
$Msg.From = $From
$Msg.To.Add($To)
$Msg.Subject = $Subject
$Msg.Body = $Body
$Msg.IsBodyHTML = $true
$MTA.send($Msg)



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>