我可以使用以下代码运行存储过程并将其导出到 csv:
function TestSQLStoredPrc()
{
$connString = "Data Source=xxxxxx,1433;Initial Catalog=TestDB;User Id=TestUser; Password=YYYYYYY;"
$Reference = Read-Host "Enter Name";
$QueryText = "exec dbo.GetUsersCountByName 'Test'";
$SqlConnection = new-object System.Data.SqlClient.SqlConnection;
$SqlConnection.ConnectionString = $connString;
$SqlCommand = $SqlConnection.CreateCommand();
$SqlCommand.CommandText = "EXEC dbo.GetUsersCountByName 'Test'";
$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand
$dataset = new-object System.Data.Dataset
Write-Host $DataAdapter.Fill($dataset) ' records have been exported.'
$dataset.Tables[0] | Export-CSV C:\MyReport.csv -Force -NoTypeInformation
Write-Host 'New report C:\MyReport.csv has been successfully generated'
}
TestSQLStoredPrc
我能够得到一个 csv 文件作为输出。但我需要将背景颜色和格式应用于输出 csv 文件的标题列。
谁能通过提供一些示例示例来帮助我解决此问题。
谢谢和问候, 桑托什·库马尔·帕特罗