VB Components + sql help

Status
Not open for further replies.

E3

Ars Centurion
387
Dim RSID
Dim MaxID

Set RSID = CreateObject("ADODB.Recordset")
Set MaxID = CreateObject("ADODB.Recordset")

MaxID = conn.Execute("Select MAX(bidderid)+1 from bidders")

conn.Execute "Insert into bidders(bidderid,biddername, password, " _
& "emailaddress, address, csz, phonenumber) values (" _
& MaxID("bidderid") & "" _
& "'" & TheRequest.Form("Username") & "', " _
& "'" & TheRequest.Form("Password") & "', " _
& "'" & TheRequest.Form("EmailAddress") & "', " _
& "'" & TheRequest.Form("Address") & "', " _
& "'" & TheRequest.Form("CSZ") & "', " _
& "'" & TheRequest.Form("PhoneNumber") & "')"


Set RSID = conn.Execute("Select Max(bidderid) as MaxID " _
& "from bidders")
TheSession("BidderID") = RSID("MaxID")

End Sub



Error Type:
ADODB.Fields (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/Register_ID.asp, line 7
 

Sans

Wise, Aged Ars Veteran
144
Just a guess but I'm thinking in these lines:
MaxID = conn.Execute("Select MAX(bidderid)+1 from bidders")

conn.Execute "Insert into bidders(bidderid,biddername, password, " _
& "emailaddress, address, csz, phonenumber) values (" _
& MaxID("bidderid") & "" _

where you call MaxID("bidderid") it has no idea what 'bidderid' is since you never aliased it in your execute call. So you need to change this:
MaxID = conn.Execute("Select MAX(bidderid)+1 from bidders")

to something like this:
MaxID = conn.Execute("Select MAX(bidderid)+1 as bidderid from bidders")

Or you could do what technophile suggested and just use the index (I like names myself :)).

.Sans
 

E3

Ars Centurion
387
I will try it later. I m now using pure asp to without using VB to do the work.


dummy1 = rsMaxID("maxid")

set dummy2 = conn.Execute("Insert into bidders(bidderid) values & dummy1")

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Line 1: Incorrect syntax near 'dummy1'.
/AddUser.asp, line 24

I have tried removing the amperson and with it. whats the correct way of including the variable (dummy1)?
 

Sans

Wise, Aged Ars Veteran
144
If you pasted your code in correctly, it looks like you misplaced a quote (and forgot some parens).

This:
set dummy2 = conn.Execute("Insert into bidders(bidderid) values & dummy1")

should be this:
set dummy2 = conn.Execute("Insert into bidders(bidderid) values(" & dummy1 & ")")

That might fix it. I personally always like to declare an extra string and build all my sql up in that so then I can just say conn.execute(strSQL). Also, this facilitates printing out the string so you can look at it (which usually results in smacking yourself in the forward and screaming "damnit!") :)

Good luck.

.Sans

EDIT: Spelling
 
Status
Not open for further replies.