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.AppSettings["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.CloseConnection);
DataGrid3.DataSource = sqlCom5.ExecuteReader();
DataGrid3.DataBind();
while(myDataReader.Read())
{
Response.ContentType = myDataReader.Items("JPEG");
Response.BinaryWrite(myDataReader.Items("InventoryItemPhoto"));
}
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
}
}
This seems to be a duplicate post, let's focus on the other one
No comments:
Post a Comment