Link to home
Start Free TrialLog in
Avatar of TeChNiCh
TeChNiCh

asked on

Trying to delete a record...

i got a little problem when i try to delete a record... i get an error saying "Invalid COUNT-Field"

this is my del code:
ID = Request.QueryString("ID")
StrSQL = "DELETE * from MyTable where ID="& ID
Set ObjRS = objConn.Execute(StrSQL)

never had that problem before, whats wrong??
ASKER CERTIFIED SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jitganguly
jitganguly

Try this

ID = Request.QueryString("ID")
if not isnumber(ID) or len(ID) > 0 Then
  StrSQL = "DELETE from MyTable where ID="& ID
  Set ObjRS = objConn.Execute(StrSQL)
else
  Response.write "Error in passing ID to SQL"
  Response.end
end if

Sorry typo

it should be if isnumber ...

ID = Request.QueryString("ID")
if isnumber(ID) or len(ID) > 0 Then
 StrSQL = "DELETE from MyTable where ID="& ID
 Set ObjRS = objConn.Execute(StrSQL)
else
 Response.write "Error in passing ID to SQL"
 Response.end
end if



I am no expert but it sounds like you have got some sort of macro or count field within your database that is denying the records deletion.

Your code appears to be fine and as you said, it has worked before.

Have you inserted any new fields in your database that utilize macros or counts?

It might also be worth checking relationships of tables just incase there is something you missed out.

Otherwise I haven't got a clue. : )
Avatar of TeChNiCh

ASKER

my mistake, just made a lil mistake on the QueryString so id was user and vice versa, thanks anyways!
So how do you intend to close this question? Both mine and jitganguly's comment hinted to you that there is something wrong with your QueryString and thus I suggest a split.

hongjun
I have had instances where I needed to cast a querystring value to a particular type, because ASP was returning it as some kind of variant.

CStr(request.querystring("value")

or CInt(request.querystring("value")
You shouldn't be using * for DELETE statements
So your code should be like this:

ID = Request.QueryString("ID")
StrSQL = "DELETE from MyTable where ID="& ID
Set ObjRS = objConn.Execute(StrSQL)

I'm assuming your ID is an integer.
Administrative Action - Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange