View Single Post
  #1 (permalink)  
Old September 19th, 2006, 10:16 AM
jazzcatone jazzcatone is offline
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 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:

  <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="">
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
  <asp:DataGrid id="DataGrid3" HorizontalAlign='Left' runat="server" AutoGenerateColumns="true"
      <asp:TemplateColumn HeaderText="Image">
            Width="150" Height="125"
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "InventoryItemPhoto")) %>'
            Runat=server />

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------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;
   SqlDataReader myDataReader;
   myDataReader = sqlCom5.ExecuteReader(CommandBehavior.CloseConnect ion);
   DataGrid3.DataSource = sqlCom5.ExecuteReader();
    Response.ContentType = myDataReader.Items("JPEG");
    Response.BinaryWrite(myDataReader.Items("Inventory ItemPhoto"));


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

  /// <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);