【发布时间】:2011-05-27 06:25:33
【问题描述】:
我希望能够右键单击文件并“发送到”本地 MSSQL 数据库。详细信息是我想将文件内容存储在“内容”列中,将文件名存储在“文件名”列中......多么新颖:)
*在大多数情况下,文件内容是 HTML。
似乎应该可以通过 Windows shell/SQL Shell 使用“shell:sendto”文件夹中命令的快捷方式。
【问题讨论】:
标签: powershell shortcut
我希望能够右键单击文件并“发送到”本地 MSSQL 数据库。详细信息是我想将文件内容存储在“内容”列中,将文件名存储在“文件名”列中......多么新颖:)
*在大多数情况下,文件内容是 HTML。
似乎应该可以通过 Windows shell/SQL Shell 使用“shell:sendto”文件夹中命令的快捷方式。
【问题讨论】:
标签: powershell shortcut
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null
$Server1 = New-Object ("Microsoft.SqlServer.Management.Smo.Server") 'SQLSERVER'
$Server1.databases["DB"].tables["Table"].rowcount
$RowCount = $server1.databases["DB"].tables["Table"].rowcount.ToString()
$TotalRecords = [int]$RowCount
$wc = New-Object system.net.WebClient
$url = ""
$files = @(Get-ChildItem c:\test\*.*)
"Number of files $($files.length)"
# Errors out when no files are found
if($files.length -lt 1) { return }
foreach($file1 in $files) {
# $txt = Get-Content($file1)
# $txt = $txt.Replace("'", "''")
# Write-Host $file1.name + " - - " + $Txt
$url1 = $url + $file1
Write-Host("URL is " + $url1)
$webpage = $wc.DownloadData($url1)
$string = [System.Text.Encoding]::ASCII.GetString($webpage)
$string = $string.Replace("'", "''")
Invoke-SqlCmd -ServerInstance SERVER -Query "Insert into DATABASE.dbo.Table(text,filename) Values ('$string','$file1')"}
【讨论】: