小编Art*_*ka1的帖子

如何使用PowerShell从SQL Server中的.csv导入数据?

我有以下场景:我使用PowerShell并且必须将.csv文件中的数据导入到SQL Server数据库上已创建的表中.所以我不需要csv的标题行,只需写入数据.

这是我到目前为止所做的:

#Setup for SQL Server connection
#SQL Server Name
$SQLServer = "APPLIK02\SQLEXPRESS"
#Database Name
$SQLDBName = "code-test"

#Create the SQL Connection Object
$SQLConn = New-Object System.Data.SQLClient.SQLConnection
#Create the SQL Command Object, to work with the Database
$SQLCmd = New-Object System.Data.SQLClient.SQLCommand

#Set the connection string one the SQL Connection Object
$SQLConn.ConnectionString = "Server=$SQLServer;Database=$SQLDBName; Integrated Security=SSPI"
#Open the connection
$SQLConn.Open()

#Handle the query with SQLCommand Object
$SQLCmd.CommandText = $query
#Provide the open connection to the Command Object as a property …
Run Code Online (Sandbox Code Playgroud)

sql-server powershell

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

powershell ×1

sql-server ×1