Solved

ASP.net VB.net Insert picture into SQL database

Posted on 2016-10-18
6
91 Views
Last Modified: 2016-10-19
Hi

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?

Thanks
0
Comment
Question by:murbro
[X]
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
6 Comments
 
LVL 28

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

0
 

Author Comment

by:murbro
ID: 41849522
Hi

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

Accepted Solution

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

sample from my code...


/*
##SUMMARY  
##REMARKS 
##RETURNS 
*/
ALTER PROCEDURE [data].[OpenCustomerCreditReport]
(	
	 @ClientIdentifier BIGINT
	,@ValidFor [data].[DateSlot]	
)
AS 
BEGIN
SET NOCOUNT ON

	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
	
END

Open in new window

0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

Author Comment

by:murbro
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
0
 
LVL 28

Expert Comment

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

Author Closing Comment

by:murbro
ID: 41849901
Thanks for the help. I can work out the rest
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

749 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