Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2004, 02:16 PM
Authorized User
 
Join Date: Jun 2003
Location: Crowland, Lincs, United Kingdom.
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.

Reply With Quote
  #2 (permalink)  
Old March 17th, 2004, 01:21 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
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.
Reply With Quote
  #3 (permalink)  
Old March 17th, 2004, 08:58 AM
Authorized User
 
Join Date: Jun 2003
Location: Crowland, Lincs, United Kingdom.
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.

Reply With Quote
  #4 (permalink)  
Old March 27th, 2004, 04:51 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:07 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.