adding to db

M

mike

I bought 3 books and spent weeks trying to add a record to
my database, but haven't figured it out??? I've tried both
sql and addnew method, but to no avail. Below is my sql
method. Any ideas would be highly appreciative.

<% @Language=VBScript %>
<% Option Explicit %>
<% Response.Expires = 0 %>
<%
Dim objConn, objRS, strQ
set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DRIVER={Microsoft Access Driver
(*.mdb)};" & _

"DBQ=c:\home\mike\www\data\data.mdb"
objConn.Open
strQ = "INSERT INTO appointments (name) VALUES ('mike')"
objConn.Execute strQ
set objRS = objConn.Execute("SELECT * FROM appointments")
%>
<html>
<body>
<%
objRS.Close : objConn.close
Set objRS = Nothing : set objConn = Nothing
%>
</body>
</html>
 
T

Tom B

I'd use a different connection string.
objConn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\home\mike\www\data\data.mdb;"

see www.connectionstrings.com


I assume your database has a table called appointments with a field called
name in it.
try
strQ="INSERT INTO appointments([name]) VALUES('mike')"
as I'm sure name is a reserved word

move your "set objRS=" to ....
<html>
<body>
<%
Set objRS=objConn.Execute("SELECT [name] FROM appointments")
Do While not objRS.EOF
Response.Write "<LI>" & objRS.Fields("name").value & "</LI>" &
vbCrLF 'note no [ ] here
objRS.MoveNext
Loop
Set objRS=nothing 'note you don't close the Recordset......because
you didn't open it.
objConn.Close
Set objCOnn=nothing
%>
</body>
</html>
 
R

Robb Meade

...
I bought 3 books and spent weeks trying to add a record to
my database, but haven't figured it out??? I've tried both
sql and addnew method, but to no avail. Below is my sql
method. Any ideas would be highly appreciative.

[snip]

Getting any specific errors or is it returning a white page with no text but
yet not adding the data?

more info needed.

Regards

Robb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top