|
-
Feb 19th, 2007, 04:58 PM
#1
Thread Starter
Member
[2005] How to store Image in SQL Server 2005
Hey everybody ,
can anyone tell me How to store Image in SQL Server 2005 using Visual Basic 2005.
-
Feb 19th, 2007, 05:14 PM
#2
Re: [2005] How to store Image in SQL Server 2005
Create a MemoryStream, Save the Image to the stream, Seek to the beginning of the stream, then get the data from the stream into a Byte array. The Byte array is the object you save to the database. When retrieving the data you use the converse operaions. I've posted code to do this previously, so a search will turn it up for you.
-
Feb 19th, 2007, 05:16 PM
#3
Lively Member
Re: [2005] How to store Image in SQL Server 2005
This is straight out of 101 MSFT VB .Net Applications, so you might need to fiddle with it a bit but here goes:
(this is something i always want to try )
On Button Press Event
VB Code:
Dim ms as New MemoryStream()
picSave.Image.Save(ms, picSave.Image.RawFormat)
Dim arrImage() as Byte = ms.GetBuffer
ms.Close()
Dim strFileName as String = lblFilePath.text.Substring(lblFilePath.Text.LastIndexOf('|") + 1)
Dim cnn as New SqlConnection(connectionString)
Dim strSQL as String = _
"INSERT INTO Picture (Filename, Picture)" & _
"VALUES (@Filename, @Picture)"
Dim cmd as NewSQLCommand(strSQL, cnn)
With cmd
.Parameters.Add(New SqlParameter("@Filename", _
SqlDbType.NVarChar, 50)).Value = strFileName
.Parameters.Add(New SqlParameter("@Picture", _
SqlDbType.Image)).Value = arrImage
End With
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close
I hope this helps
Using Visual Studio .NET 2003
QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-- Rick Cook, The Wizardry Compiled
-
Feb 20th, 2007, 01:29 AM
#4
Lively Member
Re: [2005] How to store Image in SQL Server 2005
When you create the table to store your pictures in SQL2005 declare the field to store images as Varbinary(MAX) instead of Image.
-
Jun 23rd, 2007, 06:22 AM
#5
Frenzied Member
Re: [2005] How to store Image in SQL Server 2005
what is the Technical difference of storing images between varbinary(max) and binary ??? i am just curious
-
Jun 23rd, 2007, 06:52 AM
#6
Frenzied Member
Re: [2005] How to store Image in SQL Server 2005
 Originally Posted by maged
what is the Technical difference of storing images between varbinary(max) and binary ??? i am just curious 
http://msdn2.microsoft.com/en-us/library/ms188362.aspx
-
Jun 23rd, 2007, 06:55 AM
#7
Frenzied Member
Re: [2005] How to store Image in SQL Server 2005
 Originally Posted by Shardox
When you create the table to store your pictures in SQL2005 declare the field to store images as Varbinary(MAX) instead of Image. 
I was going to ask why (as they are identical) but found the answer here:
http://msdn2.microsoft.com/en-us/library/ms187993.aspx
"ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. For more information, see Using Large-Value Data Types."
-
Jun 24th, 2007, 09:11 AM
#8
Frenzied Member
Re: [2005] How to store Image in SQL Server 2005
Thank you for the Link
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|