Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 May 31st, 2004, 05:32 AM
Authorized User
 
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to display images ?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script Language="c#" runat="server">
void Page_Load()
{
  string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
  strConnection += @"Data Source=C:\BegASPNET\ch12\Northwind.mdb";
  data_src.Text = strConnection;
  string strSQL = "SELECT FirstName,LastName, LinkPicture FROM Employees";
  string strResultsHolder = "";
  OleDbConnection objConnection = new OleDbConnection(strConnection);
  OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);
  OleDbDataReader objDataReader = null;
  try
  {
    objConnection.Open();
    con_open.Text="Connection opened successfully.<br>";
    objDataReader = objCommand.ExecuteReader();
    while (objDataReader.Read() == true)
    {
       strResultsHolder += objDataReader["FirstName"];
       strResultsHolder += "&nbsp;";
       strResultsHolder += objDataReader["LastName"];
       strResultsHolder += "<br/>";
    }
    objDataReader.Close();
    objConnection.Close();
    con_close.Text = "<br/>Connection closed.<br/>";
    divListEmployees.InnerHtml = strResultsHolder;
  }
  catch (Exception e)
  {
    con_open.Text = "Connection failed to open successfully.<br/>";
    con_close.Text = e.ToString();
  }
}
</script>
<html>
  <body>
  <h4>Reading data from the connection
  <asp:label id=data_src runat=server/> with the DataReader object.</h4>
  <asp:label id=con_open runat=server/><br>
  <div id="divListEmployees" runat="server">list will go here</div>
  <asp:label id=con_close runat=server/><br>
  </body>
</html>

This code from: chapter 12, Beginning ASP.NET 1.0 with C#.NET, WROX, datareader.aspx, let me retrieve data from a database and display them on the same page containing the code.
But how should I modify the code if one of the column of my database ( I called it LinkPicture) was a text-file, that is a path pointing to a .jpg file, and I wanted display that image with the other data on the same datareaader.aspx page?
Or should I use another code altogether!
Many Thanks Shirley65

 
Old May 31st, 2004, 06:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As far as I can see a quick solution would be something like this...
Code:
while(objDataReader.Read() == true)
{
   strResultsHolder += objDataReader["FirstName"];
   strResultsHolder += "&nbsp;";
   strResultsHolder += objDataReader["LastName"];
   strResultsHolder += "&nbsp;";
   strResultsHolder += "<img src='" + objDataReader["LinkPicture"] + "' />";
   strResultsHolder += "<br/>";
}
(not tested)

However I would probably use e.g. tables to structure the elements better, or use placeholders in the aspx page. Furthermore there is classes that enables you to add elements dynamically, so you do not have to construct the HTML string manually.

Hope it helps

Jacob.


 
Old May 31st, 2004, 08:12 AM
Authorized User
 
Join Date: May 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

many many thanks
shirley






Similar Threads
Thread Thread Starter Forum Replies Last Post
Display images from lightbox kumiko Classic ASP Basics 2 February 25th, 2008 10:19 PM
How To Display Images in DataList abdul_owiusa General .NET 4 June 3rd, 2005 11:49 AM
How To Display Images in DataList abdul_owiusa General .NET 1 May 20th, 2005 09:01 AM
Datagrid for display images sam.johnston@jtisys.com ASP.NET 1.x and 2.0 Application Design 1 January 18th, 2004 03:04 PM





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