Link to home
Start Free TrialLog in
Avatar of blakmoon91
blakmoon91Flag for United States of America

asked on

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>
              <%
              }
          %>
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Is anything being shown ? Or is it just the images that are missing ?
Avatar of blakmoon91

ASKER

Carl,
Thanks for the follow up, no nothing is being shown right now, just a blank space.
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.
Carl,
Correct, I got a no records returned error, can you give me a idea of where to start looking for a bad query?
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.
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;
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().
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>");
            }
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.
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
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.
No, no results were returned.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Appreciate your help, thanx again!!