Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

response.Write if no SQL results

Status
Not open for further replies.

jon24422531

Technical User
Jan 27, 2004
295
0
0
GB
Hi guys

I have an asp page with a SQL query that returns a result set to a table, and it works well. (Thanks mainly to all your help in the past!)
Code:
<table border='0'>
<tr>
<%
	for each fieldItem in rsData.fields
		Response.Write vbTab & vbTab &"<td bgcolor=""#EBDDE2""><strong>" & fieldItem.name
		Response.Write "</strong></td>" & vbCrLf
	next
		Response.Write vbTab & "</tr>" & vbCrLf
%>
</tr>
<%

Do While not rsData.EOF
	Response.Write "<tr>"
	for each fieldItem in rsData.fields
		if fieldItem.name = "FaultNo" then
	Response.Write "<td>&nbsp;<a href=""MyWorklogEdit.asp?id=" & fieldItem.Value & """>" & fieldItem.value & "</a></td>"
		else
	Response.Write "<td>&nbsp;" & fieldItem.value & "</td>"
		end if
	next
	Response.Write "</tr>"
	rsData.MoveNext
Loop
%>
</table>
What I am trying to do is an IF statement so that if there is no result I want to response.Write something to that effect rather than show table headers with no results.
I did try an If before the headers:
if fieldItem.name = "null" then
response.write "You have no Worklogs"
else
with an end If but it didn't work.

Can any one help with the correct syntax please?

Jonathan
 
Think this is what you are after

<%if rsDate.eof then%>
No Records
<%else%>
<table border='0'>
<tr>
<%
for each fieldItem in rsData.fields
Response.Write vbTab & vbTab &"<td bgcolor=""#EBDDE2""><strong>" & fieldItem.name
Response.Write "</strong></td>" & vbCrLf
next
Response.Write vbTab & "</tr>" & vbCrLf
%>
</tr>
<%

Do While not rsData.EOF
Response.Write "<tr>"
for each fieldItem in rsData.fields
if fieldItem.name = "FaultNo" then
Response.Write "<td>&nbsp;<a href=""MyWorklogEdit.asp?id=" & fieldItem.Value & """>" & fieldItem.value & "</a></td>"
else
Response.Write "<td>&nbsp;" & fieldItem.value & "</td>"
end if
next
Response.Write "</tr>"
rsData.MoveNext
Loop
%>
</table>
<%end if%>



}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top