使用字符串中的图像位置在sql server 2008中存储图像

时间:2011-02-26 07:47:23

标签: c# sql-server-2008

我有一张位置

的图片
string Imageloc = C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\Sunset.jpg

我使用以下查询在DB

中插入图像
"UPDATE Employee SET Image = '(SELECT * FROM OPENROWSET(BULK N'" + Imageloc + "', SINGLE_BLOB) as Image)' WHERE EmployeeID = (SELECT MAX(EmployeeID) FROM Employee";

我收到以下异常

Incorrect syntax near '\\'.\r\nIncorrect syntax near 'Employee'

请告诉我如何解决它......我不知道如何将'\\'从字符串中替换为'\'

1 个答案:

答案 0 :(得分:0)

你的意思是:

"UPDATE Employee SET Image = 
  '(SELECT * FROM OPENROWSET(BULK N'" + Imageloc + "', SINGLE_BLOB) as Image)' 
    WHERE EmployeeID = (SELECT MAX(EmployeeID) FROM Employee)";
                                                            ^