Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
USE DB
GO
CREATE TABLE Details(
Name nvarchar(255) NOT Null,
Type nvarchar(255) Null,
BinaryData varbinary(Max) Null,
Primary Key(Name)
) ON [PRIMARY]
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO

--JPEG
Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_040','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_040.jpg', Single_Blob) as T
Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_042','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_042.jpg', Single_Blob) as T
Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_053','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_053.jpg', Single_Blob) as T

Question:
I want to add more images in SQL server but each time I need to write separate Insert command for each path.
Is their any command or any tool which can add more data in SQL server.

What I have tried:

Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_040','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_040.jpg', Single_Blob) as T
Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_042','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_042.jpg', Single_Blob) as T
Insert Details([Name],[Type],[BinaryData])
Select 'IMAGE_053','Image file', BulkColumn from Openrowset( Bulk
'S:\ImageFolder\IMAGE_053.jpg', Single_Blob) as T
Posted
Comments
David_Wimbley 27-Jun-18 23:47pm    
YOur issue isn't clear, are you just asking for a way to automate the insert statements being written instead of manually writing them yourself?
Member 13889976 28-Jun-18 1:59am    
Exactly. how to automate Insert statements instead of manually?
David_Wimbley 28-Jun-18 11:28am    
So assuming you've got a directory of images, just write a console app or some sort of script to read the directory, use the file name as the image name and just build strings of inserts and write them to a file.
Member 13889976 28-Jun-18 19:43pm    
Here I don't have images in one directory or one folder.
can I retrieve images from different folder?
David_Wimbley 28-Jun-18 22:40pm    
I dont know anything about what you are trying to accomplish so your going to have to provide more info...whether its 1 directory or across 100 directories, you can write a script/console app to do the work for yourself.

Only you can figure that out given i dont have access to your PC or know anything about your project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900