我的ASP经典代码出现问题。为了让您了解流程,页面将上传图像从特定目录转到服务器,重命名该文件,然后将文件保存在SQL Server 2005的一个字段中,其中包含' image'作为数据类型。这是我的代码:
<!-- #include file="class.mssqlconnect.asp" -->
<%
Const adTypeBinary = 1
Transcode = "S12345678"
strHDLocation = "c:\test\test.bmp"
strFileURL = Server.MapPath("signatures\"& Transcode &".bmp")
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1
objADOStream.LoadFromFile strHDLocation
'Set the stream position to the start
objADOStream.Position = 0
'this will upload and save the file at the same time
objADOStream.SaveToFile strFileURL
Response.Write("Uploaded")
'if file uploaded successfully
Dim sqlRun
sqlRun = "UPDATE Bioser SET Singature = (SELECT BulkColumn FROM OPENROWSET (BULK '" & Server.MapPath("signatures\"& Transcode &".bmp") & "', SINGLE_BLOB) AS Signature) WHERE serviceno = '" & Transcode & "'"
Conn.execute(sqlRun)
Conn.close
objADOStream.Close
Set objADOStream = Nothing
%>
我能够毫无问题地上传图片,但每次我将图片保存到数据库时,它都只能保存&#34; BLANK&#34; (不是Null)在Singature领域。我没有收到任何错误消息,我之前可以保存图片(我在图片的表格字段中看到了一堆字符),我甚至启用了&#39 ; BULKADMIN&#39;我使用的SQL用户名中的角色权限...
我也尝试过使用下面的SQL语句:
"UPDATE Bioser SET Singature = (SELECT * FROM OPENROWSET(BULK '" & Server.MapPath("signatures\"& Transcode &".bmp") & "', SINGLE_BLOB) as Singature) WHERE ServiceNo = '" & Transcode & "'"
现在我已经陷入困境,我需要帮助......感谢那些回答这个问题的人。
答案 0 :(得分:1)
我能解决自己的问题,我在SQL语句中添加了“N”,来自
sqlRun = "UPDATE Bioser SET Singature = (SELECT * FROM OPENROWSET (BULK '" & Server.MapPath("signatures\"& Transcode &".bmp") & "', SINGLE_BLOB) as Singature) WHERE ServiceNo = '" & Transcode & "'"
我将其修改为:
sqlRun = "UPDATE Bioser SET Singature = (SELECT * FROM OPENROWSET (BULK N'" & Server.MapPath("signatures\"& Transcode &".bmp") & "', SINGLE_BLOB) as Singature) WHERE ServiceNo = '" & Transcode & "'"
我忘了我需要N来将图像base64字符串转换为UNICODE(NVARCHAR / NCHAR)。我的代码现在再次运行。耶!