Solved

Images not loading correctly using DB call

Posted on 2006-11-08
14
228 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now