【问题标题】:Shortcut to add files into local sql database将文件添加到本地sql数据库的快捷方式
【发布时间】:2011-05-27 06:25:33
【问题描述】:

我希望能够右键单击文件并“发送到”本地 MSSQL 数据库。详细信息是我想将文件内容存储在“内容”列中,将文件名存储在“文件名”列中......多么新颖:)

*在大多数情况下,文件内容是 HTML。

似乎应该可以通过 Windows shell/SQL Shell 使用“shell:sendto”文件夹中命令的快捷方式。

【问题讨论】:

    标签: powershell shortcut


    【解决方案1】:
    [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')"}  
    

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多