Solved

ASP.net VB.net Insert picture into SQL database

Posted on 2016-10-18
6
62 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
  • 3
  • 3
6 Comments
 
LVL 24

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 24

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 24

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now