Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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
  #1 (permalink)  
Old September 8th, 2003, 01:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default query problem

Query No1 give following error
Query 1
---------
rs.Open "SELECT contractno,recordno,category,contractor FROM arc where contractno='"&contractno&"'",cn,1,2
rs.PageSize=100

Error Type:
ADODB.Recordset (0x800A0BCD)
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
/dcil2/paging7.asp, line 27


When I change query ie.

Query 2
---------
rs.Open "SELECT contractno,recordno,category,contractor FROM arc where contractno='10 ’",cn,1,2
rs.PageSize=100

it give no error, whey ? how can use query no 1, I want to use query no.1 becasuse contractno value is dynamic (not constant)
and contractno received the value from the previous page.
  #2 (permalink)  
Old September 8th, 2003, 04:00 AM
Authorized User
 
Join Date: Jun 2003
Location: Manchester, , United Kingdom.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried a space between either side of the ampersand?

rs.Open "SELECT contractno,recordno,category,contractor FROM arc where contractno='" & contractno & "'",cn,1,2

Regards
Ian
  #3 (permalink)  
Old September 8th, 2003, 04:27 AM
Authorized User
 
Join Date: Jun 2003
Location: Edinburgh, , United Kingdom.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Although this is nothing to do with SQL question you asked but it is good practice to check if any records are being returned and deal with it appropriately :-

If rs.BOF = True And rs.EOF = True Then
raise error
else
work with recordset
end if

Nickie
  #4 (permalink)  
Old September 8th, 2003, 05:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Possibly you'd be better off using the nTRIM Functions

Code:
RTRIM(LTRIM(contractno)) ='" & contractno& "'",cn,1,2

There are two secrets to success in this world:
1. Never tell everything you know
  #5 (permalink)  
Old September 9th, 2003, 03:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response. I try

if rs.BOF = True and rs.EOF = True then
 raise error
 else
 work with recordset
 end if

but it give following error

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dcil2/paging7.asp, line 25, column 5
work with recordset
----^

I try space between either side of the ampersand,
it give same error.

I try nTRIM function, but it give same error.

query work if constand value provide,
our contractno value come from the previous page, it is change

How can use dynamic (not constant) value in query ?
contractno value received from the previous page.







Quote:
quote:Originally posted by nbryson
 Hi

Although this is nothing to do with SQL question you asked but it is good practice to check if any records are being returned and deal with it appropriately :-

If rs.BOF = True And rs.EOF = True Then
raise error
else
work with recordset
end if

Nickie

  #6 (permalink)  
Old September 9th, 2003, 05:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you actually execute the SQL from Query Analyzer?

There are two secrets to success in this world:
1. Never tell everything you know
  #7 (permalink)  
Old September 9th, 2003, 06:10 AM
Authorized User
 
Join Date: Jun 2003
Location: Edinburgh, , United Kingdom.
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

You need to replace 'raise error' and 'work with recordset' text with you own code.

if rs.BOF = True and rs.EOF = True then
  raise error
else
  work with recordset
end if

The error that was raised 'Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dcil2/paging7.asp, line 25, column 5
work with recordset' could not compile your application as it is just text.

Just to give you an idea replace the above code with :-
if rs.BOF = True and rs.EOF = True then
  msgbox "Error retrieving recordset. description = " & Err.Description
else
  msgbox "Column 1 returned is " & rs.fields(0)
end if

See how you get on.

Nickie
  #8 (permalink)  
Old September 9th, 2003, 11:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response.
I use msgbox but it give following error.

Error Type:
Microsoft VBScript runtime (0x800A0046)
Permission denied: 'msgbox'
/dcil2/tripimages/contno2ab.asp, line 107

I am using following coding.
How can use the recordset in the query ?
how can display number of records retrieve by query ?



set cn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
cn.ConnectionString="Provider=SQLOLEDB.1;Integrate d Security=SSPI;Persist Security Info=False;Initial Catalog=dcil;Data Source=dcil2"
cn.Open

contractno=Request.Form("contractno")
contractno1=Request.Form("contractno1")

ssql=contractno+contractno1

if ssql=contractno then

rs.Open "SELECT contractno,recordno,category,contractor,consultant ,Description,drawingno,approveddate,quickviewrefer ence FROM arc where contractno='" & contractno & "' order by recordno",cn,1,2
rs.PageSize=100

if rs.BOF = True and rs.EOF = True then
msgbox "error retrieving recordset. description =" & Err.Description
else
msgbox "column 1 returned is " & rs.Fields(0) // line 107

end if

Response.Write("Total No of Records = "& rs.RecordCount&"<br>")



Mateen







Quote:
quote:Originally posted by nbryson
 Hi

You need to replace 'raise error' and 'work with recordset' text with you own code.

if rs.BOF = True and rs.EOF = True then
raise error
else
work with recordset
end if

The error that was raised 'Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dcil2/paging7.asp, line 25, column 5
work with recordset' could not compile your application as it is just text.

Just to give you an idea replace the above code with :-
if rs.BOF = True and rs.EOF = True then
msgbox "Error retrieving recordset. description = " & Err.Description
else
msgbox "Column 1 returned is " & rs.fields(0)
end if

See how you get on.

Nickie


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Problem. rupen Access 3 April 27th, 2007 07:43 AM
Query Problem bundersuk VB Databases Basics 0 December 30th, 2006 07:50 AM
query problem purnendu2311 Other Programming Languages 2 December 1st, 2006 02:53 PM
problem with query harpua Classic ASP Databases 1 January 24th, 2005 12:36 PM
Problem in query leo_vinay Classic ASP Databases 5 January 21st, 2005 06:32 AM





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