Solved

ASP.net VB.net Insert picture into SQL database

Posted on 2016-10-18
6
48 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 18

Expert Comment

by:Pawan Kumar Khowal
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 18

Accepted Solution

by:
Pawan Kumar Khowal 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 18

Expert Comment

by:Pawan Kumar Khowal
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

747 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

12 Experts available now in Live!

Get 1:1 Help Now