Hey! I am new to this but trying to get it worked out, hoping to find some advice here.
My setup:
Excel 2016 64 Bit
SQL Server 2014 Import and Export Data (64-Bit)
Windows 7 64 Bit
Windows PowerShell ISE (x86)
Microsoft OLE DB Provider for SQL Server
I can export my SQL database perfectly into excel, now I’m just trying to automate it. Here is the code I am currently using:
$serverName = "E2\E2SQL"; $databaseName = "*****"; $uid ="*****" $pwd = "*****" #the save location for the new Excel file $filepath = "C:\Users\Bob\Desktop\TEST.xls"; #create a Dataset to store the DataTable $dataSet = new-object "System.Data.DataSet" "TEST" #create a Connection to the SQL Server database $cn = new-object System.Data.SqlClient.SqlConnection "server=$serverName;database=$databaseName;Integrated Security=false; User ID = $uid; Password = $pwd;" $query= "SELECT JobNo FROM Online;" #Create a SQL Data Adapter to place the resultset into the DataSet $dataAdapter = new-object "System.Data.SqlClient.SqlDataAdapter" ($query, $cn) $dataAdapter.Fill($dataSet) | Out-Null #close the connection $cn.Close()
I get an error on
$dataSet = new-object “System.Data.DataSet” “TEST”
I don’t really understand that line of code… Anyway any thoughts on how to get this working are greatly appreciated!