Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 13th, 2005, 07:51 PM
Authorized User
Points: 239, Level: 4
Points: 239, Level: 4 Points: 239, Level: 4 Points: 239, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems Displaying an image retrieved from SQL Se

Hello and thanks for taking a moment to read this message. I have a table in SQL server where I have inserted images with a Stream object and the images are stored in a table as Binary. What I am trying to do is retrieve the correct image via a querystring id that is passed to a page with a datagrid. Then I want to display it in the data grid or some other server side control. I have two pages in order to do this.
   The first page has the data grid. It selects the image. It calls a function that passes an argrument (the id of the image) to another page. It then takes the data returned by the other page and binds it to the data grid. The code in the first page with the data grid looks like this.
   <Script Runat="Server">
Public Sub Page_Load(sender As Object, e As EventArgs)
     If Not Page.IsPostBack Then
          BindGrid()
      End If
End Sub
Sub BindGrid()
   Dim intID3 As Integer
   intID3 = Int32.Parse( Request.QueryString( "id" ) )
    Dim myConnection = New SqlConnection ( "Server=localhost;uid=jazzcatone;pwd=funkdafied;da tabase=Beatles" )
    Dim myCommand = New SqlCommand("usp_retrieve_pic", myConnection)
    myCommand.CommandType = CommandType.StoredProcedure
    myCommand.Parameters.Add( "@ID", intID3 )
  Try
       myConnection.Open()
        DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
        DG_Persons.DataBind()
        Catch SQLexc As SqlException
       Response.Write("Error occured while Generating Data. Error is " & SQLexc.ToString())
End Try
End Sub
Function FormatURL(strArgument) as String Return ("readrealimages.aspx?id=" & strArgument)
End Function

</Script>
The second page ( called readrealimages.aspx) simply harnesses the image and writes it.
<Script Runat ="Server">
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim strImageID as String = Request.QueryString("id")
Dim myConnection = New SqlConnection( "Server=localhost;uid=jazzcatone;pwd=funkdafied;da tabase=Beatles" )
Dim myCommand As New SqlCommand("Select * from Pictures Where ID=" & strImageID, myConnection)
Try
  myConnection.Open()
  Dim myDataReader as SqlDataReader
  myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
  Do While (myDataReader.Read())
      Response.ContentType = myDataReader.Item("Image_Type")
      Response.BinaryWrite(myDataReader.Item("Image_NAME "))
   Loop
  myConnection.Close()
  Catch SQLexc As SqlException
  End Try
End Sub
 </Script>

Everything is processed, (I think)the page runs ( meaning it doesn't crash) but no image is displayed. I am new with working with images in SQL Server. Can someone tell me what is wrong with my code, or if there is an easier way to do this? (Perhaps with a path to the image and a Response.Write ????) Any suggestions would be appreciated . If you need a more in depth explanation, please feel free to ask.

Best Regards,
Jason


  #2 (permalink)  
Old September 3rd, 2005, 09:39 AM
Friend of Wrox
Points: 410, Level: 7
Points: 410, Level: 7 Points: 410, Level: 7 Points: 410, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: New Delhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

 hi,

 you have written that the data type is Binary. Try changing it to IMage data type in SQL Server. It should work i hope

Anubhav Kumar
  #3 (permalink)  
Old September 3rd, 2005, 09:53 AM
Friend of Wrox
Points: 410, Level: 7
Points: 410, Level: 7 Points: 410, Level: 7 Points: 410, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2004
Location: New Delhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

 can you share the code through which you are saving the images. I can't infer it from the posted code.

Anubhav Kumar
 


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
Having problems on Mozilla firefox (not able to se viral612 XSLT 0 March 12th, 2007 11:53 PM
download data ("image") from SQL database problems alex9183 Classic ASP Databases 2 September 14th, 2006 09:02 AM
download data ("image") from SQL database problems dcleslie Classic ASP Databases 9 August 29th, 2006 01:10 PM
displaying an image from file stream into an image sanjeet ADO.NET 0 September 23rd, 2005 10:28 AM
Displaying user image from sql database palvin Classic ASP Databases 14 July 6th, 2005 05:09 AM



All times are GMT -4. The time now is 02:18 AM.


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