ASP.net VB.net Insert picture into SQL database

Posted on 2016-10-18
Medium Priority
Last Modified: 2016-10-19

I have a SQL table with a varbinary column. I need a user on my webform to be able to click a button that inserts an image
into the database. If I know the path of  the database, how would the SQL statement look?

Question by:Murray Brown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41849521
Pls try .. This code will read the data from the table and save the jpg file @ E drive with name Pawan.jpg.

4 part name [PAWAN452801].[ABCInvestment].data.CreditReport ----- ServerName.DatabaseaName.Schema.TableName


	DECLARE  @Command NVARCHAR(4000)=''
	SET @Command = 'bcp " ' + 'SELECT CreditReport FROM [PAWAN452801].[ABCInvestment].data.CreditReport ' 
                   + ' queryout "E:\Pawan' + '.jpg' + '"' + ' -T -N'
	PRINT @Command
	EXEC xp_cmdshell  @Command


Open in new window


Author Comment

by:Murray Brown
ID: 41849522

Thank you. I need to do this in VB.net
LVL 29

Accepted Solution

Pawan Kumar earned 2000 total points
ID: 41849528
Create a stored procedure and call that stored procedure from VB.Net code.

sample from my code...

ALTER PROCEDURE [data].[OpenCustomerCreditReport]
	 @ClientIdentifier BIGINT
	,@ValidFor [data].[DateSlot]	

	DECLARE  @Command NVARCHAR(4000)=''
	SET @Command = 'bcp " ' + 'SELECT CreditReport FROM [PAWAN452801].[ABCInvestment].data.CreditReport WHERE CustomerId = ' +  CAST(@ClientIdentifier AS NVARCHAR(15)) 
	+ ' AND YearQuater = ' + CAST(@ValidFor AS NVARCHAR(8)) + '"'
                   + ' queryout "E:\' +  CAST(@ClientIdentifier AS NVARCHAR(15)) + CAST(@ValidFor AS NVARCHAR(8)) + '.jpg' + '"' + ' -T -N'
	PRINT @Command
	EXEC xp_cmdshell   @Command

Open in new window

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Murray Brown
ID: 41849538
Hi. Thank you for the feedback but I need this to all happen in my VB.net application because it has to work with any database from my app
LVL 29

Expert Comment

by:Pawan Kumar
ID: 41849539
ohhh okies... cool. go ahead....

Author Closing Comment

by:Murray Brown
ID: 41849901
Thanks for the help. I can work out the rest

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question