Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 September 19th, 2006, 10:16 AM
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:

<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
 }
}



  #2 (permalink)  
Old September 19th, 2006, 11:33 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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.
 


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
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



All times are GMT -4. The time now is 04:29 PM.


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