You can use the below scripts to store/save the file into SQL Server database table. Please note it is not recommended to store file into database. You can store the file on file system and path in the database.
use Testing
--documents table will store files into varbinary field
--drop table documents
create table documents
(
documentID int identity(1,1),
doctype char(5),
document varbinary(max)
)
--script to store/save document into table
insert into documents
Select 'xls', (SELECT * FROM OPENROWSET(BULK N'C:\LeaveHistoryReport.xls', SINGLE_BLOB) AS document) document
go
select * from documents
use Testing
--documents table will store files into varbinary field
--drop table documents
create table documents
(
documentID int identity(1,1),
doctype char(5),
document varbinary(max)
)
--script to store/save document into table
insert into documents
Select 'xls', (SELECT * FROM OPENROWSET(BULK N'C:\LeaveHistoryReport.xls', SINGLE_BLOB) AS document) document
go
select * from documents
No comments:
Post a Comment