Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2004, 02:16 PM
Authorized User
 
Join Date: Jun 2003
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Storing Graphic Image on Sql Server

Hi
Any one can help me with storing Graphics Image on to Sql Server. I have some success at easy bit.
When I try to use store procedure then it failed, just get "System Error".

The table, PHOTOTEST consists of these fields,
pId int INDICATOR (auto number)
photodesc nvarchar(50)
photo image

The store procedure
CREATE PROCEDURE up_InsertPhoto(@photoclip_IM image, @photodesc_V nvarchar(50) )
AS

INSERT INTO phototest
( photodesc,photo )
VALUES ( @photodesc_V,@photoclip_IM )

[u]The code is in VB.NET</u>

Dim cnnstr As String
Dim filePath As String
Dim cmd As String
Dim fsBLOB As FileStream
Dim svr As SqlDataAdapter
Dim svrConn As SqlConnection
Dim svrParams As SqlParameter

cnnstr = "data source=myserver;user id=myself;password=mypwd;initial catalog=Photos"
filePath = "D:\Photos\MyCar.jpg"
cmd = "up_InsertPhoto"

'reading the JPEG file
fsBLOB = New FileStream(filePath, FileMode.Open, FileAccess.Read)
Dim oBytes(fsBLOB.Length) As Byte
fsBLOB.Read(oBytes, 0, oBytes.Length)
fsBLOB.Close()

'connecting to server
svrConn = New SqlConnection(cnnstr)
svr = New SqlDataAdapter(cmd, svrConn)

'set 1st param
svrParams = New SqlParameter("@photoclip_IM", SqlDbType.VarBinary)
svrParams.Size = oBytes.Length
svrParams.Value = oBytes
svr.SelectCommand.Parameters.Add(svrParams)

'set 2nd param
svrParams = New SqlParameter("@photodesc_V", SqlDbType.NVarChar)
svrParams.Value = "My car photo"
svr.SelectCommand.Parameters.Add(svrParams)

'open server connection & execute query
svrConn.Open()
svr.SelectCommand.ExecuteNonQuery()

You may notice using SqlDbType.VarBinary for SQL Server Image data type, well if I replace the stored procedure with a string SQL command,
cmd = "INSERT INTO phototest (photodesc,photo) VALUES (@photodesc,@photo)"

Then replacing the parameter names repect to the above command... well it works. I had a look at the MSDN KB article 317701 that why I used to BLOB and SQL DBtype VarBinary, http://support.microsoft.com/default...b;en-us;317701

I gather that error must caused at the store procedure...but why and what reason, can any one get it to work?

Hope you can help me, thanks in advance.

Kasie.

 
Old March 17th, 2004, 01:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Im sure this will help u
http://www.codeproject.com/cs/database/albumviewer.asp

Always:),
Hovik Melkomian.
 
Old March 17th, 2004, 08:58 AM
Authorized User
 
Join Date: Jun 2003
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks melvik, looked at your article and found my problem, well I did not includes the CommandType selection to store procedure Duhhhhh... for myself.

Kasie.

 
Old March 27th, 2004, 04:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

It was not my article but Im happy that u solve ur problem by that link.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
storing image url in sql 2000 sbushe Classic ASP Databases 0 January 28th, 2008 02:28 PM
Storing & retrieving swf file from sql server tarduk2004 ASP.NET 2.0 Basics 2 October 30th, 2007 02:31 AM
storing serialized object in sql server ACE2084 General .NET 0 October 13th, 2005 01:35 PM
syntax for storing chr(0) in sql server through vb neeraj.khattar Beginning VB 6 1 January 10th, 2005 02:20 PM
Storing E-Invoices (pdf-files) in SQL-Server Gert SQL Server 2000 1 September 17th, 2004 09:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.