Solved

Images not loading correctly using DB call

Posted on 2006-11-08
14
230 Views
Last Modified: 2010-04-16
Group,
Wanted to ask you a question, we are trying to have some images pulled and displayed on the footer of the website, however for some reason there is nothing showing up. I have included the code below, can you take a quick look through and let me know your thoughts, I am not a heavy .Net programmer and I am trying to fix what someone else broke.

 <!--#include file ="includes/footer_movie.asp"-->
        <td width="333" height="112"><table cellpadding="0" cellspacing="0" class="showcase">
            <tr>
              <%
            while ( dr_ft.Read() )
            {
        %>
              <td class="prod"><a href="productdetail.aspx?iid=<%=dr_ft.GetString(0)%>" title="Fun Friends Cover Details"> <img src="<%=dr_ft.GetString(4)%>" width="75" height="75" border="0" /></a><br/>
                <table cellpadding="0" cellspacing="0" align="center">
                  <tr>
                    <td><a href="productdetail.aspx?iid=<%=dr_ft.GetString(0)%>" title="click for Details"><%=dr_ft.GetString(1)%></a></td>
                  </tr>
                </table></td>
              <%
              }
          %>
0
Comment
Question by:blakmoon91
  • 7
  • 7
14 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17899458
Is anything being shown ? Or is it just the images that are missing ?
0
 

Author Comment

by:blakmoon91
ID: 17899491
Carl,
Thanks for the follow up, no nothing is being shown right now, just a blank space.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17899560
That would suggest that your query is not returning anything. To test change your code to:

 <!--#include file ="includes/footer_movie.asp"-->
        <td width="333" height="112"><table cellpadding="0" cellspacing="0" class="showcase">
            <tr>
              <%
          int count = 0;
          while ( dr_ft.Read() )
          {
               ++count;
        %>
              <td class="prod"><a href="productdetail.aspx?iid=<%=dr_ft.GetString(0)%>" title="Fun Friends Cover Details"> <img src="<%=dr_ft.GetString(4)%>" width="75" height="75" border="0" /></a><br/>
                <table cellpadding="0" cellspacing="0" align="center">
                  <tr>
                    <td><a href="productdetail.aspx?iid=<%=dr_ft.GetString(0)%>" title="click for Details"><%=dr_ft.GetString(1)%></a></td>
                  </tr>
                </table></td>
              <%
            }
            if (count == 0) Response.Write("No records returned");
          %>


If you get the "No records returned" message then you will need to look at your query to establish why nothing is being returned.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:blakmoon91
ID: 17899595
Carl,
Correct, I got a no records returned error, can you give me a idea of where to start looking for a bad query?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17899637
I guess the code you have posted is not the full content of the file, so it should either be further up the page, or inside one of your include files.

You'll be looking for a line of code that probably starts with:

    SqlDataReader dr_ft =

The "Sql" part of "SqlDataReader" may say "OleDb" or "Odbc" if you are not using SQL Server. This is just a guess tho, depending on how the code has been put together the DataReader may be being returned by another object. But you should definatley start by searching for "dr_ft =".

Ordinarily the DataReader will be a result of calling the ExecuteReader() method of a Command object. It is the Command object that you need to find as it is that that will hold the SQL Query that is being executed.
0
 

Author Comment

by:blakmoon91
ID: 17899844
Carl,
Found a piece of code that matches what you are talking about on the code behind page, it has protection around it, anything to do with it?

protected System.Data.SqlClient.SqlDataReader dr_ft;

        public WebForm1()
        {
            Page.Init += new System.EventHandler(Page_Init);
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            System.Data.SqlClient.SqlConnection cn_ft;
            System.Data.SqlClient.SqlCommand cmd_ft;
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17899879
protected doesn't mean protected in the sense you are thinking :o)  "protected" in this case means that the variable/method is private to anything except this class or any class that derives from it.

That certainly looks like the place to start. I would guess that cmd_ft is what you are looking for; somewhere there is probably a line that starts:

    cmd_ft.CommandText =

Try and find that next, it may be somewhere in Page_Load().
0
 

Author Comment

by:blakmoon91
ID: 17899929
Found the Page_Load() command, didn't see anything about a CommandText, have a look, again appreciate your input

 protected void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            System.Data.SqlClient.SqlConnection cn_ft;
            System.Data.SqlClient.SqlCommand cmd_ft;

            string connectionInfo = System.Configuration.ConfigurationManager.AppSettings["DBConnectionString"];
               
            cn_ft = new SqlConnection(connectionInfo);

            cmd_ft = new SqlCommand("usp_s_categoryitems", cn_ft);
            cmd_ft.CommandType = CommandType.StoredProcedure;

            cmd_ft.Parameters.AddWithValue("@cid", "1");
            cmd_ft.Parameters.AddWithValue("@catid", "9");


            try
            {
                cn_ft.Open();
                dr_ft = cmd_ft.ExecuteReader(CommandBehavior.CloseConnection);

            }
            catch (System.Data.SqlClient.SqlException sqle)
            {
                //internalmessage.Text = sqle.ToString().Replace("\n", "<BR>");
            }
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17899949
Ah, ok. Your code is using a stored procedure called "usp_s_categoryitems" and passing the values 1 and 9 respectively into its parameters. You would need to examine the stored proc itself to see what it is doing and what effect the parameters have.
0
 

Author Comment

by:blakmoon91
ID: 17900095
OK, i took a look at the stored procedure, I don't know if anything is wrong with the code, may have to do with categories begin active, and inventory in stock. What do you think? We are using a test DB right now that might not have a value or value of zero for inventory

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[usp_s_categoryitems]
      @cid            int,
      @catid            varchar(12)
AS


begin

      select       ltrim(str(i.iid)) as iid,
            i.name,
            i.description,
            i.r_price as price,
            i.rootimagepath + i.productimagepath + i.smallimage as image
      from       t_item i, t_catitem ci
      where ci.catid = @catid
            and ci.iid = i.iid
            and i.status = 'a'
            and (i.inventoryremove = 'off' or
             (i.inventoryremove = 'on' and i.inventory > 0) )

end
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17900575
Its a little strange that the stored proc takes two parameters but only uses one of them. You may want to run the stored proc in Enterprise Manager to see the results:

    EXEC usp_s_categoryitems 1, '9'

And see if any results come back. Other than that you would have to manually check the tables in the query to see if any records match the correct criteria:

    1) t_catitem = '9'
    2) ci.iid = i.iid

etc.
0
 

Author Comment

by:blakmoon91
ID: 17901060
No, no results were returned.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 275 total points
ID: 17901185
In that case there is no problem with your code at all. You just don't have any data that matches the query, I can't really advise you on whether or not there should be any data :)
0
 

Author Comment

by:blakmoon91
ID: 17901240
Appreciate your help, thanx again!!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where can I ask about my ASP.NET MVC project? 6 36
Reading the Web.Config using IIS 7.5? 4 35
Keyboard 2 33
SSRS subreport with parameter 3 32
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question