Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Images not loading correctly using DB call

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
blakmoon91
Asked:
blakmoon91
  • 7
  • 7
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Is anything being shown ? Or is it just the images that are missing ?
0
 
blakmoon91Author Commented:
Carl,
Thanks for the follow up, no nothing is being shown right now, just a blank space.
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
blakmoon91Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
blakmoon91Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
blakmoon91Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
blakmoon91Author Commented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
blakmoon91Author Commented:
No, no results were returned.
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
blakmoon91Author Commented:
Appreciate your help, thanx again!!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now