INSERT INTO cartproducts(Photo)SELECT*FROMOPENROWSET(BULKN'F:\New folder\StudentManagement\StudentManagement\images\Baby\bed.jpg',SINGLE_BLOB)
got error as
A correlation name must be specified for the bulk rowset in the from clause.
so gave an alias
and wrote the query as below
INSERT INTO cartproducts(Photo)SELECT*FROMOPENROWSET(BULKN'F:\New folder\StudentManagement\StudentManagement\images\Baby\bed.jpg',SINGLE_BLOB)
as Photo
but again got error as
Msg 515, Level 16, State 2, Line 2
Cannot insert the value NULL into column 'Pid', table 'Northwind.dbo.cartproducts'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Here pid is one column name in table cartproducts.
There are 5 columns in my table i wanted to insert image into photo column as all other columns have already data.
A correlation name must be specified for the bulk rowset in the from clause.
In order to resolve your issue, please modify the code as follows:
CREATE TABLE myTable(Document varbinary(max))
INSERT INTO myTable(Document)
SELECT * FROM
OPENROWSET(BULK N'E:\Project\WebSite5\image\5.jpg', SINGLE_BLOB) as imagefile
Best wishes,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Its now coming correctly but what I did is instead of storing the image itself i am now storing the image path in my table and able to retrieve the image in my gridview
fanu
Member
3 Points
16 Posts
query to store image in sql server database
Dec 22, 2012 06:06 PM|LINK
i have few images which i need to insert into a column of a table in sql server database.
the column name is Image and its type is image.
Can anybody help me in wrtitng a query which can insert image into the Image column.
The important point is the image should be stored in bytes format.
Thanks in advance.
XIII
All-Star
182690 Points
23458 Posts
ASPInsiders
Moderator
MVP
Re: query to store image in sql server database
Dec 22, 2012 06:25 PM|LINK
Hi,
you can do it like this:
Note that Image1.jpg should be on the same server as where your sql server runs.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
fanu
Member
3 Points
16 Posts
Re: query to store image in sql server database
Dec 23, 2012 10:44 AM|LINK
Hi,
tried this
INSERT INTO cartproducts(Photo) SELECT * FROM OPENROWSET(BULK N'F:\New folder\StudentManagement\StudentManagement\images\Baby\bed.jpg', SINGLE_BLOB)
got error as
A correlation name must be specified for the bulk rowset in the from clause.
so gave an alias
and wrote the query as below
INSERT INTO cartproducts(Photo) SELECT * FROM OPENROWSET(BULK N'F:\New folder\StudentManagement\StudentManagement\images\Baby\bed.jpg', SINGLE_BLOB) as Photo
but again got error as
Msg 515, Level 16, State 2, Line 2
Cannot insert the value NULL into column 'Pid', table 'Northwind.dbo.cartproducts'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Here pid is one column name in table cartproducts.
There are 5 columns in my table i wanted to insert image into photo column as all other columns have already data.
Please help
Thanks in advance
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: query to store image in sql server database
Dec 26, 2012 05:26 AM|LINK
Hi,
In order to resolve your issue, please modify the code as follows:
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
eralper
Contributor
6048 Points
971 Posts
Re: query to store image in sql server database
Dec 26, 2012 02:05 PM|LINK
Hello fanu,
Please check the SQL article at http://www.kodyaz.com/t-sql/save-image-to-database-table-in-sql-server.aspx
I believe it may help you,
SQL Server 2012
fanu
Member
3 Points
16 Posts
Re: query to store image in sql server database
Dec 30, 2012 06:19 PM|LINK
Thanks to everyone for helping me
Its now coming correctly but what I did is instead of storing the image itself i am now storing the image path in my table and able to retrieve the image in my gridview
Thanks for helping