我在Web服务器上的磁盘上有图像,我想在经典的asp(vbscript)中编写一个脚本,该脚本将获取图像并将其保存在MSSQL(2005)数据库(图像数据类型列)中。 SQL数据库位于不同的服务器上
任何帮助都将不胜感激。
谢谢,
答案 0 :(得分:0)
MSSQL image数据类型是“byte []”数组
byte[] buffer = File.ReadAllBytes("Path to file");
现在使用此缓冲区插入MSSQL表图像列
现在MSSQL命令就像这样
SqlCommand cmd = new SqlCommand("INSERT INTO <your_table_name> (ImageColumn) values (@parameter)");
cmd.Parameters.AdWithValues("@parameter",buffer);
答案 1 :(得分:0)
感谢您的帮助。我想我在经典ASP
中想出了如何做到这一点strFilePath = Server.MapPath("your file")
Set oConn = Server.CreateObject("ADODB.Connection")
With oConn
.connectiontimeout = 0
.commandtimeout = 0
.connectionstring = <your connection string>
.cursorlocation = 3 'adUseClient
.open
End With
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1 'AdBinary
oStream.Open
oStream.LoadFromFile strFilePath
xBin = oStream.Read
Set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = oConn
strSql = "INSERT INTO dbo.YourTable (strImage) VALUES(?);"
oCmd.CommandText = strSql
oCmd.Parameters.Item(0) = xBin
Set oRs = oCmd.Execute
Set oRs = Nothing
Set oStream = Nothing
Set oConn = Nothing