p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2000 (http://p2p.wrox.com/forumdisplay.php?f=20)
-   -   query problem (http://p2p.wrox.com/showthread.php?t=3590)

mateenmohd September 8th, 2003 01:26 AM

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.

ioates September 8th, 2003 04:00 AM

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

nbryson September 8th, 2003 04:27 AM

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

chrislepingwell September 8th, 2003 05:04 AM

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

mateenmohd September 9th, 2003 03:17 AM

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



chrislepingwell September 9th, 2003 05:53 AM

Can you actually execute the SQL from Query Analyzer?

There are two secrets to success in this world:
1. Never tell everything you know

nbryson September 9th, 2003 06:10 AM

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

mateenmohd September 9th, 2003 11:58 PM

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



All times are GMT -4. The time now is 02:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.