• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

ASP.net VB.net Insert picture into SQL database

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
Murray Brown
Asked:
Murray Brown
  • 3
  • 3
1 Solution
 
Pawan KumarDatabase ExpertCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi

Thank you. I need to do this in VB.net
0
 
Pawan KumarDatabase ExpertCommented:
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
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
 
Pawan KumarDatabase ExpertCommented:
ohhh okies... cool. go ahead....
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help. I can work out the rest
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now