• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

Insert Statement Help

I am trying to insert a record into an access table using ASP.  What I have so far does not work.  There are no errors, but nothing gets inserted.



      x_AccessDate = date()
      x_AccessTime = time()
      x_AccessIP = Request.serverVariables("REMOTE_ADDR")

' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str

strsql = "INSERT INTO Log (AccessDate, AccessTime, AccessIP) VALUES (x_AccessDate, x_AccessTime, x_AccessIP)"

            Set rstemp = Server.CreateObject("ADODB.Recordset")
            'rstemp.Insert strsql, conn


conn.Close ' Close Connection
Set conn = Nothing
0
Insomniac_PhD
Asked:
Insomniac_PhD
  • 4
1 Solution
 
Yrag1Commented:
Try this
            
dim Conn
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open xDb_Conn_Str
dim strsql
strsql = "INSERT INTO Log (AccessDate, AccessTime, AccessIP) VALUES (x_AccessDate, x_AccessTime, x_AccessIP)"
Conn.Execute (strsql)
Conn.close
set Cconn = nothing

Gary
0
 
fritz_the_blankCommented:
Try this instead:

strsql = "INSERT INTO Log (AccessDate, AccessTime, AccessIP) VALUES ('" & x_AccessDate & "', '" & x_AccessTime & "','" &  x_AccessIP & "')"


FtB
0
 
fritz_the_blankCommented:
So now your code will look like:

x_AccessDate = date()
x_AccessTime = time()
x_AccessIP = Request.serverVariables("REMOTE_ADDR")

' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
strsql = "INSERT INTO Log (AccessDate, AccessTime, AccessIP) VALUES ('" & x_AccessDate & "', '" & x_AccessTime & "','" &  x_AccessIP & "')"
conn.execute(strsql)
conn.close
set conn=Nothing


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fritz_the_blankCommented:
You can bypass all of the variables altogether like this:

' Open connection to the database
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
strsql = "INSERT INTO Log (AccessDate, AccessTime, AccessIP) VALUES ('" & Date () & "', '" & Time() & "','" &  Request.serverVariables("REMOTE_ADDR") & "')"
conn.execute(strsql)
conn.close
set conn=Nothing


FtB
0
 
Insomniac_PhDAuthor Commented:
Thanks Fritz.
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now