简体   繁体   English

如何将Excel文件插入到具有varbinary类型的列到SQL表中?

[英]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.

相关问题 如何在Excel Server 2008的varbinary(max)列中插入/检索Excel文件? - How do I insert/retrieve Excel files to varbinary(max) column in SQL Server 2008? 如何将文件(PDF)插入到varbinary SQL Server列中,然后检索它? - How do you insert a file (PDF) into a varbinary SQL Server column and later retrieve it? 如何在Varbinary类型的sql server表列中存储字节数组? - How a byte array is being stored in sql server table column of type Varbinary? SQL Server查询与varbinary类型列不匹配 - SQL Server query not matching for a varbinary type column 如何将 Byte[] 转换为数据以在 SQL Server 的 varbinary(max) 列中插入值? - How convert a Byte[] to a data to insert a value in a varbinary(max) column in SQL Server? 有没有一种方法可以将C#字符串插入SQL varbinary列中? - Is there a way to insert a C# string into a SQL varbinary column? 如何使用 SSIS 将文档(文本、csv、excel)或 BLOB 文件加载到 varbinary(MAX) 数据库列中 - How to load a document(text,csv,excel) or BLOB file into a varbinary(MAX) database column using SSIS 在SQL中反序列化varbinary列 - Deserialize varbinary column in SQL 如何在 sql 表的新多列表中插入特定列 - how to insert into specific column in a new multi column table in sql table 如何在 SQL Server 中存储和检索 varbinary(max) 列 - How to Store and Retrieve a varbinary(max) Column in SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM