473,509 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL asp select syntax help

Hi

I am a relative beginner with ASP and weak on syntax for sql
statements. Basically I modify something which works.

I have tblGroupContact with two fields both long integer - ContactID &
GroupID

I am using asp3.0 and VB Script

I have a querystring from another page with the url
http://localhost/gc6/www/LeaveGroup....D=82&groupID=1

With my poor syntax knowledge I have written the following SQL
statement (modified from one which works OK elsewhere):

strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = "&
Replace(Request.QueryString("ContactID")) AND GroupID = "&
Replace(Request.QueryString("GroupID"))"

I get the error message:
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/gc6/www/LeaveGroup.asp, line 34, column 149
strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = "&
Replace(Request.QueryString("ContactID")) AND GroupID = "&
Replace(Request.QueryString("GroupID"))"

Any help would be appreciated.

Thanks Colin

Nov 13 '05 #1
6 2261
Br
ia****@gmail.com wrote:
Hi

I am a relative beginner with ASP and weak on syntax for sql
statements. Basically I modify something which works.

I have tblGroupContact with two fields both long integer - ContactID &
GroupID

I am using asp3.0 and VB Script

I have a querystring from another page with the url
http://localhost/gc6/www/LeaveGroup....D=82&groupID=1

With my poor syntax knowledge I have written the following SQL
statement (modified from one which works OK elsewhere):

strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = "&
Replace(Request.QueryString("ContactID")) AND GroupID = "&
Replace(Request.QueryString("GroupID"))"

I get the error message:
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/gc6/www/LeaveGroup.asp, line 34, column 149
strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = "&
Replace(Request.QueryString("ContactID")) AND GroupID = "&
Replace(Request.QueryString("GroupID"))"

Any help would be appreciated.

Thanks Colin


First, I'd seperate out the components of your code so that you will get
a more accurate look at where the code fails.

eg.

Dim Contact as Long
Dim Group as Long
Dim strSQL as String
Contact = Replace(Request.QueryString("ContactID"))
Group = Replace(Request.QueryString("GroupID"))
strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = " & Contact
AND GroupID = " & Group

Your replace statements seem to be missing arguments...

I used this....

'clean up input

dim regEX

set regEx = New RegExp

regEx.Global = true

regEx.Pattern = "[^0-9a-zA-Z]"

pid = regEx.Replace(Request.Form("pid"), "")

pass = regEx.Replace(Request.Form("pass") , "")

cid = regEx.Replace(Request.Form("company") , "")

set reEx = nothing

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2
Hi Bradley

That worked fine (slightly modified form another NG reply). However,
the record successfully deletes but I get the error message

"Row handle referred to a deleted row or a row marked for deletion"

I am using access 2002

Full code below.

If you have any more suggestions for me, I would grealtly appreciate
your help.

I am in quite a hurry, and presume you are in bed now (I'm in UK), so I
will also post a new message.

Thanks Colin

<%
' LeaveGroup.asp is called by LeaveGroupSelect.asp and deletes the
selected record from the database-->

'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGC1 'Holds the recordset for the record to be deleted
Dim strSQL 'Holds the SQL query to query the database
Dim GroupID
Dim ContactID

'Read in the GroupID to be deleted
GroupID = Request.QueryString("GroupID")

'Read in the ContactID to be deleted
ContactID = Request.QueryString("ContactID")

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("../databases/GC1.mdb")

'Create an ADO recordset object
Set rsGC1 = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database

strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = " & ContactID
& " AND GroupID = " & GroupID

'Set the lock type so that the record is locked by ADO when it is
deleted
rsGC1.LockType = 3

'Open the recordset with the SQL query
rsGC1.Open strSQL, adoCon

'Remove this group from the members list
rsGC1.Delete

'The response.write's below were used to verify the values below - when
setting up sql
' When activated they confirm that the correct values are being
modified / deleted
'and the correct record is actually deleted from the database - beu
then I get the error message
'Row handle referred to a deleted row or a row marked for deletion
%>
'<%Response.Write (rsGC1("ContactID"))%><p>
'<%Response.Write (rsGC1("GroupID"))%><p>

'<%Response.Write ContactID%><P>
'<%Response.Write GroupID%><P>

<%
'Reset server objects
rsGC1.Close
Set rsGC1 = Nothing
Set adoCon = Nothing

Response.Redirect "LeaveGroupconfirm.asp"
%>

Nov 13 '05 #3
Br
ia****@gmail.com wrote:
Hi Bradley

That worked fine (slightly modified form another NG reply). However,
the record successfully deletes but I get the error message

"Row handle referred to a deleted row or a row marked for deletion"
Because you are trying to read field values from the record you just
deleted???
I am using access 2002

Full code below.

If you have any more suggestions for me, I would grealtly appreciate
your help.

I am in quite a hurry, and presume you are in bed now (I'm in UK), so
I will also post a new message.

Thanks Colin

<%
' LeaveGroup.asp is called by LeaveGroupSelect.asp and deletes the
selected record from the database-->

'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGC1 'Holds the recordset for the record to be deleted
Dim strSQL 'Holds the SQL query to query the database
Dim GroupID
Dim ContactID

'Read in the GroupID to be deleted
GroupID = Request.QueryString("GroupID")

'Read in the ContactID to be deleted
ContactID = Request.QueryString("ContactID")

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("../databases/GC1.mdb")

'Create an ADO recordset object
Set rsGC1 = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the
database

strSQL = "SELECT * FROM tblGroupContact WHERE ContactID = " &
ContactID & " AND GroupID = " & GroupID

'Set the lock type so that the record is locked by ADO when it is
deleted
rsGC1.LockType = 3

'Open the recordset with the SQL query
rsGC1.Open strSQL, adoCon

'Remove this group from the members list
rsGC1.Delete

'The response.write's below were used to verify the values below -
when setting up sql
' When activated they confirm that the correct values are being
modified / deleted
'and the correct record is actually deleted from the database - beu
then I get the error message
'Row handle referred to a deleted row or a row marked for deletion
%>
'<%Response.Write (rsGC1("ContactID"))%><p>
'<%Response.Write (rsGC1("GroupID"))%><p>

'<%Response.Write ContactID%><P>
'<%Response.Write GroupID%><P>
I'm not sure I understand what you're saying but you can't try to read
field values from the record that you just deleted... ?
<%
'Reset server objects
rsGC1.Close
Set rsGC1 = Nothing
Set adoCon = Nothing

Response.Redirect "LeaveGroupconfirm.asp"
%>


--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #4
Hi Bradley

Thanks for your response again. I have now got it working.

Sorry if my enquiry was not clear.

The response.write's below were there to help me verify what was
happening to the variables. When actually running the page to delete
the record I thought the ' would comment the line and hence I thought I
was not trying to read the record - however I now realise the <%
effectively superceded the ' - hence the error.

With these deleted it works fine.
'<%Response.Write (rsGC1("ContactID"))%><p>
'<%Response.Write (rsGC1("GroupID"))%><p>

'<%Response.Write ContactID%><P>
'<%Response.Write GroupID%><P>


This is a college project, I have a few more pages to finish / modify.
Would you mind if I ask you some more questions?

Can I contact you directly? or do you prefer that I use the newsgroup.

I can't quite work out your email address from the NG. If I can contact
you directly please email me at ia****@gmail.com

I will only hassle you a few times over the next week - 10 days - then
I will be finished.

In any event, thanks for your help thus far.

Thanks Colin

Nov 13 '05 #5
Br
ia****@gmail.com wrote:
Hi Bradley

Thanks for your response again. I have now got it working.

Sorry if my enquiry was not clear.

The response.write's below were there to help me verify what was
happening to the variables. When actually running the page to delete
the record I thought the ' would comment the line and hence I thought
I was not trying to read the record - however I now realise the <%
effectively superceded the ' - hence the error.

With these deleted it works fine.
Sorry I shoulda mentioned that! :)
'<%Response.Write (rsGC1("ContactID"))%><p>
'<%Response.Write (rsGC1("GroupID"))%><p>

'<%Response.Write ContactID%><P>
'<%Response.Write GroupID%><P>

This is a college project, I have a few more pages to finish / modify.
Would you mind if I ask you some more questions?

Can I contact you directly? or do you prefer that I use the newsgroup.
Posting here is probably beneficial for others and gives the opportunity
for people with better answers to provide them.
I can't quite work out your email address from the NG.
That's cause it's fake LOL.
If I can
contact you directly please email me at <address removed>
Tut tut :)

It is a _big_ mistake to publish your email on a public forum especially
on Usenet. Email addresses are harvested automatically by spammers and
you'll find your inbox will fill up with junk. if you must publish your
address then disguise it by puttin gin some fake characters.

eg. my***********@mailserver.com or myemailATmailserverDOTcom

And even then it's wise to have a seperate web based "throw away" mail
account fo using in public forums (eg. if it starts filling up with junk
ditch it for a new one and publish it, disguised of course, in your
future posts).

I get zero spam in my two main, real accounts (work/private).
I will only hassle you a few times over the next week - 10 days - then
I will be finished.

In any event, thanks for your help thus far.

Thanks Colin


I'm no expert on ASP pages but I've managed to code an online app (like
a basic bank site but only reporting statements, managing logins, etc at
the moment).
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #6
Hi Bradley

Thanks for your reply.

my iam247 email address is only used for newsgroups and I find gmail is
quite good at dealing with spam,if you had been willing to communicate
directly I would have done so via a different email ac., however I will
take your advice and disguise it in google.

Thanks again Colin

Br@dley wrote:
ia****@gmail.com wrote:
Hi Bradley

Thanks for your response again. I have now got it working.

Sorry if my enquiry was not clear.

The response.write's below were there to help me verify what was
happening to the variables. When actually running the page to delete
the record I thought the ' would comment the line and hence I thought
I was not trying to read the record - however I now realise the <%
effectively superceded the ' - hence the error.

With these deleted it works fine.


Sorry I shoulda mentioned that! :)
'<%Response.Write (rsGC1("ContactID"))%><p>
'<%Response.Write (rsGC1("GroupID"))%><p>

'<%Response.Write ContactID%><P>
'<%Response.Write GroupID%><P>

This is a college project, I have a few more pages to finish / modify.
Would you mind if I ask you some more questions?

Can I contact you directly? or do you prefer that I use the newsgroup.


Posting here is probably beneficial for others and gives the opportunity
for people with better answers to provide them.
I can't quite work out your email address from the NG.


That's cause it's fake LOL.
If I can
contact you directly please email me at <address removed>


Tut tut :)

It is a _big_ mistake to publish your email on a public forum especially
on Usenet. Email addresses are harvested automatically by spammers and
you'll find your inbox will fill up with junk. if you must publish your
address then disguise it by puttin gin some fake characters.

eg. my***********@mailserver.com or myemailATmailserverDOTcom

And even then it's wise to have a seperate web based "throw away" mail
account fo using in public forums (eg. if it starts filling up with junk
ditch it for a new one and publish it, disguised of course, in your
future posts).

I get zero spam in my two main, real accounts (work/private).
I will only hassle you a few times over the next week - 10 days - then
I will be finished.

In any event, thanks for your help thus far.

Thanks Colin


I'm no expert on ASP pages but I've managed to code an online app (like
a basic bank site but only reporting statements, managing logins, etc at
the moment).
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response


Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3057
by: sam | last post by:
When I run this SQL query: SELECT u.*, o.* FROM users u, orders o WHERE TO_DAYS(o.order_date) BETWEEN TO_DAYS('2003-09-20')-10 AND TO_DAYS('2003-09-20')+10
23
5641
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
9
3612
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
1
595
by: Craig Stadler | last post by:
Can someone help with query syntax regarding IN/EXISTS.. I'm trying to do this: insert into table2 (field1) select field1 from table1 where field1 not in (select field1 from table2) delete...
3
6425
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
10493
by: Michael Turner | last post by:
Hi Can anyone help me with my syntax please. This is not working. Set rs = conn.Execute("SELECT * FROM tblCompany WHERE company like '*" & txt_search & "*';") Thanks in advance Mick
1
5821
by: bpforte | last post by:
Hello, I need help with building query, basically I need to select all records from one table that don't exists in second table with status 1, but they can exists in second table with status 0, to...
17
3108
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
2
3395
by: kxyz | last post by:
Hello everyone, I need help with a stored procedure or two. My stored procedures are supposed to check if a certain record exists. If it does exist, then I select everything from that row, as...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.