0

Hi I am new to ASP and I am trying to build SQL on fly in my page.

 sSQL = "SELECT " sSQL = sSQL & " Message1," sSQL = sSQL & " Message2" sSQL = sSQL & " FROM table1" sSQL = sSQL & " WHERE" sSQL = sSQL & " name = '" & customname & "'" Set serverobject = Server.CreateObject("ADODB.Recordset") serverobject .Open sSQL, conn message1 = serverobject ("Message1") message2 = serverobject ("Message2") response.Write message1 response.Write message2 

Here whats happening is customname is name entered by user and I am comparing with my name column in table table1.

If it matched then everything is working fine and I am getting proper result.

But if customname doesn't match with name then I am getting this error :

Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

What I got to know if I should check for null somehow while calling query and if it contains result then only proceed. Can someone help me how can i achieve this .

1 Answer 1

1

You must check for rows before reading from the recordset, for example using .eof:

if (serverobject.eof) then ''// no matching rows else message1 = serverobject("Message1") message2 = serverobject("Message2") end if 

Also as your not using a parametrized statement don't forget to sanitize the string in the customname variable.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.