Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 31st, 2004, 05:32 AM
Authorized User
 
Join Date: May 2004
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old May 31st, 2004, 06:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Copenhagen, , Denmark.
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.


Reply With Quote
  #3 (permalink)  
Old May 31st, 2004, 08:12 AM
Authorized User
 
Join Date: May 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

many many thanks
shirley

Reply With Quote
Reply


Thread Tools
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
Display images from lightbox kumiko Classic ASP Basics 2 February 25th, 2008 09: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 02:04 PM



All times are GMT -4. The time now is 09:53 PM.


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