all groups > dotnet clr > july 2005 >
You're in the

dotnet clr

group:

How to store and retreive images from SQL server?



Re: How to store and retreive images from SQL server? Mrinal Kamboj
7/27/2005 12:00:00 AM
dotnet clr: See the code below :

I have not tested , it got it from somewhere on net , so , can't promise

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("Select * from ImgTable where imageid="
& imgId, myConnection)
Dim fs As FileStream
myConnection.Open()
Dim myDataReader As SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Response.ContentType = myDataReader.Item("imgtype")
Response.BinaryWrite(myDataReader.Item("imageid"))
Loop
above code will display the image on the same page.
------------------------------------------------------------------------
if you want to write that file locally
Dim fs As FileStream
myConnection.Open()
Dim myDataReader As SqlDataReader
myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Dim buffer() As Byte
buffer = myDataReader.Item("imageid")
If Not File.Exists("c:\temp\testing.bmp") Then
fs = New FileStream("c:\temp\testing.bmp", FileMode.Create)
fs.Write(buffer, 0, buffer.Length)
fs.Close()
End If



[quoted text, click to view]
How to store and retreive images from SQL server? Mukilan.Ps.
7/27/2005 5:41:06 AM
Hi,

" Retreiving and showing Image to the client side"

I'm doing web application using ASP.Net, and code behind VB.Net. SQL server
2000 is the Back end. I'm facing the problem when i retreive the image from
the database and showing the image in the Web page. How to retreive the
image from the database and how to display? Please help me out and give me
some solution.


AddThis Social Bookmark Button