blakmoon91
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.as p"-->
<td width="333" height="112"><table cellpadding="0" cellspacing="0" class="showcase">
<tr>
<%
while ( dr_ft.Read() )
{
%>
<td class="prod"><a href="productdetail.aspx?i id=<%=dr_f t.GetStrin g(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?i id=<%=dr_f t.GetStrin g(0)%>" title="click for Details"><%=dr_ft.GetStrin g(1)%></a> </td>
</tr>
</table></td>
<%
}
%>
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.as
<td width="333" height="112"><table cellpadding="0" cellspacing="0" class="showcase">
<tr>
<%
while ( dr_ft.Read() )
{
%>
<td class="prod"><a href="productdetail.aspx?i
<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td><a href="productdetail.aspx?i
</tr>
</table></td>
<%
}
%>
Is anything being shown ? Or is it just the images that are missing ?
ASKER
Carl,
Thanks for the follow up, no nothing is being shown right now, just a blank space.
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.as p"-->
<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?i id=<%=dr_f t.GetStrin g(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?i id=<%=dr_f t.GetStrin g(0)%>" title="click for Details"><%=dr_ft.GetStrin g(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.
<!--#include file ="includes/footer_movie.as
<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?i
<table cellpadding="0" cellspacing="0" align="center">
<tr>
<td><a href="productdetail.aspx?i
</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.
ASKER
Carl,
Correct, I got a no records returned error, can you give me a idea of where to start looking for a bad query?
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.
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.
ASKER
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.SqlD ataReader dr_ft;
public WebForm1()
{
Page.Init += new System.EventHandler(Page_I nit);
}
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
System.Data.SqlClient.SqlC onnection cn_ft;
System.Data.SqlClient.SqlC ommand cmd_ft;
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.SqlD
public WebForm1()
{
Page.Init += new System.EventHandler(Page_I
}
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
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().
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().
ASKER
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.SqlC onnection cn_ft;
System.Data.SqlClient.SqlC ommand cmd_ft;
string connectionInfo = System.Configuration.Confi gurationMa nager.AppS ettings["D BConnectio nString"];
cn_ft = new SqlConnection(connectionIn fo);
cmd_ft = new SqlCommand("usp_s_category items", cn_ft);
cmd_ft.CommandType = CommandType.StoredProcedur e;
cmd_ft.Parameters.AddWithV alue("@cid ", "1");
cmd_ft.Parameters.AddWithV alue("@cat id", "9");
try
{
cn_ft.Open();
dr_ft = cmd_ft.ExecuteReader(Comma ndBehavior .CloseConn ection);
}
catch (System.Data.SqlClient.Sql Exception sqle)
{
//internalmessage.Text = sqle.ToString().Replace("\ n", "<BR>");
}
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
System.Data.SqlClient.SqlC
System.Data.SqlClient.SqlC
string connectionInfo = System.Configuration.Confi
cn_ft = new SqlConnection(connectionIn
cmd_ft = new SqlCommand("usp_s_category
cmd_ft.CommandType = CommandType.StoredProcedur
cmd_ft.Parameters.AddWithV
cmd_ft.Parameters.AddWithV
try
{
cn_ft.Open();
dr_ft = cmd_ft.ExecuteReader(Comma
}
catch (System.Data.SqlClient.Sql
{
//internalmessage.Text = sqle.ToString().Replace("\
}
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.
ASKER
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
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.
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.
ASKER
No, no results were returned.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Appreciate your help, thanx again!!