17 October,2019 by Tom Collins
Question: i'm working with Powershell System.Data.DataTable to get values from a SQL Server to generate a report for DBAs. the report is sent via email to the DBA team. As part of the email subject - I'd like to add the row count as a summary - so the DBAs don't need to always click into the email - i.e they only need to click in if there is a row count greater than 0.
How can I get the row count from System.Data.DataTable ?
Answer: When you use the Powershell Powershell System.Data.DataTable , certain properties are available . One those properties is the Rows.Count . This is an example of how you might use it.
Note: The Rows.Count will return an int , so it will be necessary to cast as a string if you want to add it to the email subject line
#create a powershell system data table
$dt = new-object "System.Data.DataTable"
#do some stuff to add rows
#get the datatable row count
$dt.Rows.Count
#convert to a string with ToString()
$var1 = $dt.Rows.Count
$var1.ToString()
Read more on Powershell Datatable
How to add a row in Powershell System.Data.Datatable
Powershell insert into sql table
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |