Ask a Question related to ASP Database, Design and Development.
-
Dave Posh #1
Problem inserting a autonumber value from a recordset to another table as text
The problem I'm having is I'm trying to insert a number value (UserID)
obtained from the first SQL1 query from a table called User. In the
Access database the column UserID is a autonumber. I'm taking that
value and storing it as a variable in ASP using vbscript.
Set RSlookup = conn.execute(SQL1)
UserID = RSlookup("UserID")
This works because when I test it using a response.write UserID it
displays the value I want.
However, when I run SQL2 which tries to insert the Use rid variable
into another table called Connections as text all of the data inserts
except the Userid.
When it test the query by changing the variable to Userid = 1234 the
insert statemnet works inserting all the data.
I believe my problem lies with the UserID = RSlookup("UserID"), the
UserID is not being stored as text or a number.
Note: Im using Access 2003 database is in 2000 format
************************************************** ***************
SQL1 = "SELECT * FROM User WHERE Name='"&Name&"'"
SQL2 = "INSERT INTO Connections (UserID, InternalIP, ExternalIP,
TimeofConnection, DateOfConnection) Values("_
& "'" & UserID & "', "_
& "'" & local & "', "_
& "'" & external & "', "_
& "'" & timeofuser & "', "_
& "'" & dateofuser& "')"
'Queries the table Users and then stores UserID from a recordset into
a variable called UserID
conn.open connstring
Set RSlookup = conn.execute(SQL1)
UserID = RSlookup("UserID")
conn.close
'Inserts Info including the UserID from UserID variable obtain by SQL1
conn.open connstring
conn.execute(SQL2)
conn.close
Dave Posh Guest
-
Problem inserting arabic caracters in SQL server table
I have a problem when trying to insert arabic characters in SQL Server data base from a Coldfusion MX 7 cfml page. All arabic sent characters to... -
recordset table names problem
I just upgraded to CF 7 and now my table names show up as a file path instead of just the table name in Dreamweaver when creating new recordsets. ... -
Simple Problem - Inserting current date into table
Hello Im trying to create a form in which when someone registers, it also adds the current date into a specified field from a hiddenfield... -
DELETE table and reset AutoNumber
I'm using MS-Access and was wondering if there's a way to DELETE a table and reset the primary key which is an AutoNumber field. If I do "DELETE... -
Inserting text box into a form, displaying values from recordset
I'm trying to create a form that allows me to modify the contents of list. When the user clicks on the modify button, it takes them to a page which... -
Bob Barrows [MVP] #2
Re: Problem inserting a autonumber value from a recordset to another table as text
Dave Posh wrote:
At this point, UserID HAS NO VALUE>
> ************************************************** ***************
>
>
> SQL1 = "SELECT * FROM User WHERE Name='"&Name&"'"
>
> SQL2 = "INSERT INTO Connections (UserID, InternalIP, ExternalIP,
> TimeofConnection, DateOfConnection) Values("_
> & "'" & UserID & "', "_
:-)
Move this code to after the line of code where you give UserID a value.
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Bob Barrows [MVP] Guest
-
Aaron [SQL Server MVP] #3
Re: Problem inserting a autonumber value from a recordset to another table as text
> SQL1 = "SELECT * FROM User WHERE Name='"&Name&"'"
Where are all of these values populated??? Do they come from the User>
> SQL2 = "INSERT INTO Connections (UserID, InternalIP, ExternalIP,
> TimeofConnection, DateOfConnection) Values("_
> & "'" & UserID & "', "_
> & "'" & local & "', "_
> & "'" & external & "', "_
> & "'" & timeofuser & "', "_
> & "'" & dateofuser& "')"
table, some other part of the ASP script, thin air?
--
[url]http://www.aspfaq.com/[/url]
(Reverse address to reply.)
Aaron [SQL Server MVP] Guest
-
Dave Posh #4
Re: Problem inserting a autonumber value from a recordset to another table as text
Here is my full code.
<%
dim conn
dim connstring
Set conn = Server.CreateObject("ADODB.Connection")
connstring = "DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=C:\databasefile\rcontrol.mdb"
%>
<%
Function WriteToDB(IP)
dim SQL1
dim SQL2
dim SQL3
dim RSlookup
dim UserID
dim local
dim external
dim Name
dim Branch
dim ext
dim dateofuser
dim timeofuser
local = IP
Name = Request.form("nametxt")
Branch = Request.form("branchtxt")
ext = Request.form("exttxt")
external = Request.ServerVariables("REMOTE_ADDR")
dateofuser = date()
timeofuser = time()
SQL1 = "SELECT * FROM User WHERE Name='"&Name&"'"
SQL2 = "INSERT INTO Connections (UserID, InternalIP, ExternalIP,
TimeofConnection, DateOfConnection) Values("_
& "'" &UserID& "', "_
& "'" & local & "', "_
& "'" & external & "', "_
& "'" & timeofuser & "', "_
& "'" & dateofuser& "')"
SQL3 = "INSERT INTO User (Name, Branch, Phone, DateofUser, TimeOfUser)
Values("_
& "'" & Name & "', "_
& "'" & Branch & "', "_
& "'" & ext & "', "_
& "'" & dateofuser & "', "_
& "'" & timeofuser & "')"
conn.open connstring
Set RSlookup = conn.execute(SQL1)
if RSlookup.eof then
conn.execute(SQL3)
conn.close
conn.open
Set RSlookup = conn.execute(SQL1)
UserID = RSlookup("UserID")
conn.close
conn.open connstring
response.write userid
conn.execute(SQL2)
conn.close
else
UserID = RSlookup("UserID")
conn.close
conn.open connstring
response.write userid
conn.execute(SQL2)
conn.close
end if
dim fs, f
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.CreateTextFile("c:\website\batch\"&Name&".bat", true)
f.WriteLine("c:\progra~1\radmin\radmin.exe /connect:"&local&"
/Through:"&external )
f.Close
set f=nothing
set fs=nothing
response.write "<a href=""batch/"&Name&".bat"">"&Name&"</a></p>"
end function
Dave Posh Guest
-
Bob Barrows [MVP] #5
Re: Problem inserting a autonumber value from a recordset to another table as text
What's the problem? I didn't make myself clear enough?
Look, you can't create SQL2 until AFTER you open the recordset on SQL1 and
assign a value to UserID. Is that clearer? Like this:
SQL1 = " ... "
Set RSlookup = conn.execute(SQL1)
UserID = RSlookup("UserID")
SQL2 = " ... "
etc.
Bob Barrows
Dave Posh wrote:--> Here is my full code.
>
> <%
> dim conn
> dim connstring
>
> Set conn = Server.CreateObject("ADODB.Connection")
> connstring = "DRIVER={Microsoft Access Driver
> (*.mdb)};DBQ=C:\databasefile\rcontrol.mdb"
> %>
>
> <%
> Function WriteToDB(IP)
> dim SQL1
> dim SQL2
> dim SQL3
> dim RSlookup
> dim UserID
> dim local
> dim external
> dim Name
> dim Branch
> dim ext
>
>
> dim dateofuser
> dim timeofuser
>
> local = IP
> Name = Request.form("nametxt")
> Branch = Request.form("branchtxt")
> ext = Request.form("exttxt")
>
>
>
> external = Request.ServerVariables("REMOTE_ADDR")
>
> dateofuser = date()
> timeofuser = time()
>
>
> SQL1 = "SELECT * FROM User WHERE Name='"&Name&"'"
>
> SQL2 = "INSERT INTO Connections (UserID, InternalIP, ExternalIP,
> TimeofConnection, DateOfConnection) Values("_
> & "'" &UserID& "', "_
> & "'" & local & "', "_
> & "'" & external & "', "_
> & "'" & timeofuser & "', "_
> & "'" & dateofuser& "')"
>
> SQL3 = "INSERT INTO User (Name, Branch, Phone, DateofUser, TimeOfUser)
> Values("_
> & "'" & Name & "', "_
> & "'" & Branch & "', "_
> & "'" & ext & "', "_
> & "'" & dateofuser & "', "_
> & "'" & timeofuser & "')"
>
> conn.open connstring
>
> Set RSlookup = conn.execute(SQL1)
>
> if RSlookup.eof then
> conn.execute(SQL3)
> conn.close
>
> conn.open
> Set RSlookup = conn.execute(SQL1)
> UserID = RSlookup("UserID")
> conn.close
>
> conn.open connstring
> response.write userid
> conn.execute(SQL2)
>
> conn.close
>
> else
>
> UserID = RSlookup("UserID")
> conn.close
> conn.open connstring
> response.write userid
> conn.execute(SQL2)
> conn.close
>
> end if
>
>
>
> dim fs, f
> set fs = Server.CreateObject("Scripting.FileSystemObject")
> set f = fs.CreateTextFile("c:\website\batch\"&Name&".bat", true)
> f.WriteLine("c:\progra~1\radmin\radmin.exe /connect:"&local&"
> /Through:"&external )
>
> f.Close
> set f=nothing
> set fs=nothing
>
> response.write "<a href=""batch/"&Name&".bat"">"&Name&"</a></p>"
>
>
> end function
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Bob Barrows [MVP] Guest
-
Dave Posh #6
Re: Problem inserting a autonumber value from a recordset to another table as text
Thanks Bob, works great!
Dave Posh Guest



Reply With Quote

