p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Professional (http://p2p.wrox.com/forumdisplay.php?f=57)
-   -   Retrieving Images from SQL Server (http://p2p.wrox.com/showthread.php?t=48027)

jazzcatone September 19th, 2006 10:16 AM

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="http://schemas.microsoft.com/intellisense/ie5">
 <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);


dparsons September 19th, 2006 11:33 AM

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.

All times are GMT -4. The time now is 03:10 PM.

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