将从Web网址获取的图像插入SQL Server [英] Insert image taken from a web url into SQL Server
本文介绍了将从Web网址获取的图像插入SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Web上远程获取了一个图像到我的< asp:Image>
中,现在我想将该图像插入SQL Server.请帮忙!我有一个简单的表 id(pk)
,我的 image(image)
I remotely took an image from web into my <asp:Image>
, now I want to insert that image into SQL Server. Please help! I have a simple table id (pk)
, my image (image)
或者当唯一可用的是图像URL时,是否可以将从Web获取的图像插入SQL Server图像数据类型?
Or is it possible to insert image taken from web into SQL Server image datatype when only thing available to you is image url ?
谢谢
推荐答案
使用C#从URL下载图像
要使用WebClient,您可能需要包括System.Net命名空间.
For using WebClient you might need to include the System.Net namespace.
WebClient wc = new WebClient();
wc.DownloadFile(URL_Of_The_Image, FileName_You_Want_to_Store_It_As);
使用OPENROWSET将图像上传到SQL Server表中
CREATE TABLE EmployeeProfile
(
EmpId INT,
EmpName VARCHAR(50) not null,
EmpPhoto VARBINARY(MAX) not null
)
GO
INSERT EmployeeProfile (EmpId, EmpName, EmpPhoto)
SELECT 1001, 'Vadivel', BulkColumn
FROM OPENROWSET( BULK 'C:\Images\Demo.jpg', Single_Blob) AS EmployeePicture
GO
引用- http://vadivel.blogspot.in/2005/10/saving-images-as-blob-into-sql-server.html
这篇关于将从Web网址获取的图像插入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文