Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2005, 01:59 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Query returning 0 results although SQL is valid

Hi!
I am trying to get supplier address by searching on companyName of the suppliers table of northwind database.The company name is filled in a list box the code for which is not shown here.

My following query runs in SQL query analyzer and it also shows the query properly when i use reposne.write.However the query returns 0 results when i execute it in the ASP page.

please tell me whats going wrong.

thanks


dim cname,MyQuery

'replace all quotes in company name with double qutes
cname= Replace(Request.Form("CompanyName"), "'", "''")


MyQuery = " Select CompanyName, Address from NorthWind.dbo.Suppliers where CompanyName like '" & cname &"'"

Response.Write(MyQuery)

set rs=server.CreateObject("ADODB.Recordset")
conn.Open

set rs=conn.Execute(MyQuery)
if(rs.EOF) then
           Response.write "<br><b>nuthin"
else
     Response.Write "<br>my address is " &rs("address")
end if


 
Old March 24th, 2005, 02:45 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

are you getting any errors? does "nuthin" is displaying as part of your code
also, hard code company name in your query and see if you are getting any results.. let me know

 
Old March 24th, 2005, 07:36 PM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi

thanks for your reply.

yes I am getting output as 'nuthing'.I hard coded query with company name='exotic liquids' and it gave me proper output of rs("address")
only when i use a variable its giving me poutput as 'nothing'





 
Old March 25th, 2005, 11:46 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When you response.write the query what do you get? Paste this into query analyser and see if it runs.

Your code will only match on exact name, if you want "begins with" then add a percentage sign:
MyQuery = " Select CompanyName, Address from NorthWind.dbo.Suppliers where CompanyName like '" & cname & "%'"

I would use a stored procedure. It's safer and you don't need to worry about replacing quotes etc.




--

Joe (Microsoft MVP - XML)
 
Old March 31st, 2005, 11:06 AM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@ joefawcett

Your solution solved my problem! Thanx

webkasper






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL returning odd results jakeone SQL Language 1 November 13th, 2006 05:07 AM
$sql not returning results, this cant be this hard cspgsl Beginning PHP 0 May 5th, 2006 11:50 AM
Temp Table Query not returning results to page rlull SQL Server 2000 1 November 15th, 2005 04:50 PM
Returning Oracle SELECT query results to DataSet gp_mk ADO.NET 0 December 17th, 2003 11:08 AM
Query not returning correct results from database Jams30 PHP Databases 5 November 7th, 2003 08:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.