[英]How to insert an Excel file to a column with varbinary type into an SQL table?
I have a table: Formats 我有一张桌子:格式
with columns: 列:
FileName,Document_binary,Format,UsedBy,Date and Id FileName,Document_binary,Format,UsedBy,Date和Id
Document column is VARBINARY(MAX). 文档列是VARBINARY(MAX)。
There are some already loaded documents with names like: 0x504b34xxxx and so on, all of these are excel files that users can download from a site. 有一些已加载的文档,其名称如下:0x504b34xxxx等,所有这些都是用户可以从站点下载的excel文件。
What I am trying to accomplish is to have this file formar, the file itself stored in the database for when a user needs the file go get it from the system as a download. 我想要完成的是拥有这个文件formar,文件本身存储在数据库中,当用户需要文件时,从系统下载它。 Not the data contained in it but the file itself. 不是包含在其中的数据,而是文件本身。
I need to do it manually without any interface. 我需要手动完成它,没有任何接口。
I tried this below with no luck: 我试过这个没有运气:
INSERT INTO Formats
(FileName, Document_binary,Format,UploadUser,UploadDateTime,Id)
values
('Case_Project', * FROM OPENROWSET(BULK 'C:\Users\jhon\Desktop\Worksheet
in 6W2H update Jul2018 formato std.xlsx'),
'Template','jhon.doe',NOW,22)
Thank you 谢谢
SELECT * INTO Formats (FileName, Document_binary,Format,UploadUser,UploadDateTime,Id)
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0; Database=C:\Users\jhon\Desktop\Worksheet_in_6W2H_update_Jul2018_formato_std.xlsx; HDR=YES; IMEX=1','SELECT * FROM [Sheet1$]');
Keep the file name without space. 保留文件名,不留空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.