我被困住了。我正在尝试将图片从硬盘插入到 SQL Server 类型的列中VARBINARY(MAX)
。我把它转换成某种东西,但我什至不确定它是什么。结果看起来像“81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81 69 20 0 81”,但更长。在我的更新命令中,如果我将 $file 替换为 01234 ,则更新不会出现任何问题,所以我几乎可以确定将其转换为正确的格式(无论是什么)。
$i = 1
$shape|foreach{
if ($shape.Item($i).name.Substring(0, 7) -eq 'Picture')
{
#write-host $shape.Item($i).name
$shape.Item($i).copy()
#write-host $firstChart.name
$firstChart.paste()
$firstChart.Export("c:\temp\pictures\image1.jpg", "JPG")
#$firstChart.Delete
[Byte[]]$file = get-content -Encoding Byte C:\TEMP\pictures\image1.jpg
#$file = [convert]::ToBase64String((get-content C:\TEMP\pictures\image1.jpg -encoding byte))
$cmd.CommandText ="UPDATE QuoteData SET PII_Image1 = $file Where QuoteNumber = '"+$WorkSheet.Range('G7').Text.replace("'","''")+"'"
$cmd.ExecuteNonQuery()
}
$i++
}
您的字节数组需要转换为十六进制表示形式。请注意 $hexString 行已添加,并且 $cmd.CommandText 已更改。
[Byte[]]$file = get-content -Encoding Byte C:\TEMP\pictures\image1.jpg
$hexString = ($file|ForEach-Object ToString X2) -join ''
$hexString = '0x'+$hexString
$cmd.CommandText ="UPDATE QuoteData SET PII_Image1 = $hexString Where QuoteNumber = '"+$WorkSheet.Range('G7').Text.replace("'","''")+"'"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)