Forums
This topic is locked
Insert into DB without a form
Posted 15 Mar 2002 12:15:21
1
has voted
15 Mar 2002 12:15:21 Mat Burhouse posted:
Hi I've got some session variables that i want to insert into a DB. Can this be done without the use of a form so the page inserts the new record every time a page is visited?
Cheers
Replies
Replied 15 Mar 2002 18:28:12
15 Mar 2002 18:28:12 Michael Rudge replied:
yes. you just need to create a function or sub procedure to handle the insert and pass it the session variables. like this:
strSession = Session("myVariable"
'strConn is the connection string I have this type of procedure in an include file
Sub Insert_Physcian(strSession, strConn)
Set DBConn = Server.CreateObject("ADODB.Connection"
DBConn.Open(strConn)
Set rsSession = Server.CreateObject("ADODB.Recordset"
rsSession.Open "myTable", DBConn, ADOPENSTATIC, adLockOptimistic
rsSession.Addnew
rsSession("info"=strSession
rsSession.Update
rsSession.Close
Set rsSession = Nothing
DBConn.Close
Set DBConn = Nothing
End sub
hope this helps
Michael Rudge
strSession = Session("myVariable"
'strConn is the connection string I have this type of procedure in an include file
Sub Insert_Physcian(strSession, strConn)
Set DBConn = Server.CreateObject("ADODB.Connection"
DBConn.Open(strConn)
Set rsSession = Server.CreateObject("ADODB.Recordset"
rsSession.Open "myTable", DBConn, ADOPENSTATIC, adLockOptimistic
rsSession.Addnew
rsSession("info"=strSession
rsSession.Update
rsSession.Close
Set rsSession = Nothing
DBConn.Close
Set DBConn = Nothing
End sub
hope this helps
Michael Rudge
Replied 15 Mar 2002 18:48:10
15 Mar 2002 18:48:10 Mat Burhouse replied:
Cheers Michael!