Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 September 19th, 2006, 10:16 AM
Authorized User
 
Join Date: Jul 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Retrieving Images from SQL Server

Hello and thanks for taking a moment. I am trying to retrieve and display an image that is stored in SQL Server 2000. My aspx code is as follows:

<HTML>
 <HEAD>
  <title>photoitem</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
  <asp:DataGrid id="DataGrid3" HorizontalAlign='Left' runat="server" AutoGenerateColumns="true"
  Visible="True">
     <Columns>
      <asp:TemplateColumn HeaderText="Image">
        <ItemTemplate>
            <asp:Image
            Width="150" Height="125"
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "InventoryItemPhoto")) %>'
            Runat=server />
        </ItemTemplate>
    </asp:TemplateColumn>
     </Columns>
  </asp:DataGrid>
  </form>
 </body>
</HTML>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------My code behind file is below VS 2003 does not like my datareader. It says the following:

 'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'Items'

If there are any suggestions as to what I am doing wrong I would appreciate the input. - Jason

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

namespace ActionLinkAdHoc
{
 /// <summary>
 /// Summary description for photoitem.
 /// </summary>
 public class photoitem : System.Web.UI.Page
 {
  string connStr = System.Configuration.ConfigurationSettings.AppSett ings["ConnectionString"];
        protected System.Web.UI.WebControls.DataGrid DataGrid3;
  private void Page_Load(object sender, System.EventArgs e)
  {
   // Get the querystring ID
   string item =Request.QueryString["ID"];
   int ID=Convert.ToInt32(item);

   SqlConnection dbConn5 = new SqlConnection(connStr);
   SqlCommand sqlCom5 =new SqlCommand("sp4TWRetrieveItemPhotos");
   sqlCom5.Connection = dbConn5;
   sqlCom5.CommandType = CommandType.StoredProcedure;
   sqlCom5.Parameters.Add("@ID", SqlDbType.Int);
   sqlCom5.Parameters["@ID"].Value =ID;
   dbConn5.Open();
   SqlDataReader myDataReader;
   myDataReader = sqlCom5.ExecuteReader(CommandBehavior.CloseConnect ion);
   DataGrid3.DataSource = sqlCom5.ExecuteReader();
            DataGrid3.DataBind();
   while(myDataReader.Read())
   {
    Response.ContentType = myDataReader.Items("JPEG");
    Response.BinaryWrite(myDataReader.Items("Inventory ItemPhoto"));
     }
    dbConn5.Close();



    }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}



 
Old September 19th, 2006, 11:33 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try: myDataReader("JPEG") though in C# it may actually be this: myDataReader["JPEG"]

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing & retrieving swf file from sql server tarduk2004 ASP.NET 2.0 Basics 2 October 30th, 2007 02:31 AM
how to display sql server images in asp.net c# bobwith5 ASP.NET 2.0 Basics 0 October 20th, 2007 11:07 AM
Inserting & Retrieving Images on Sql Server adamusufi SQL Server 2000 6 June 26th, 2005 03:32 PM
Inserting Images and retrieving from SQL SERVER adamusufi VB.NET 2002/2003 Basics 0 June 24th, 2005 04:13 AM
images in sql server rj1406 ASP.NET 1.0 and 1.1 Basics 1 September 28th, 2004 05:50 AM





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