PDA

View Full Version : AddNew


fsamejimcom
09-17-2003, 01:37 AM
I'm new to ASP.
I can't add a record to my access db.
My code is in below. What would be the problem?
==========================
<%@ LANGUAGE="VBScript" %>
<% Option Explicit %>
<%
Const adOpenForwardOnly=0
Const adLockOptimistic=3
Const adLockPessimistic=2
Const adLockReadOnly=1
Const adCmdTable=2
Dim objConn
Dim objRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=fsamejimcom_mjs.dsn;uid=******;pwd=p****"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "studentInfo", objConn, , adLockOptimistic, adCmdTable
objRS.AddNew
objRS("familyID")="2"
objRS("studentName")="Sammy"
objRS("class")="4"
objRS.Update
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

==============================
By the way, I can view the data by the code below.
==============================
<%@ LANGUAGE="VBScript" %>
<% Option Explicit %>
<%
Const adOpenForwardOnly=0
Const adLockOptimistic=3
Const adLockPessimistic=2
Const adLockReadOnly=1
Const adCmdTable=2
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=fsamejimcom_mjs.dsn;uid=*******;pwd=******"
Dim objRS
Set objRS=Server.CreateObject("ADODB.Recordset")
objRS.Open "studentInfo", objConn, , , adCmdTable
Do While Not objRs.EOF
%>

<%= objRS.Fields("studentName").Value %></ br>
<%= objRS.Fields("id").Value %></ br>
<%= objRS.Fields("FamilyID").Value %></ br>
<%= objRS.Fields("class").Value %></ br>
<%
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

bruce
09-17-2003, 04:49 AM
Did you name the page with .asp extension?


You should never be able to view the code

[b]quote:Originally posted by fsamejimcom

I'm new to ASP.
I can't add a record to my access db.
My code is in below. What would be the problem?
==========================
<%@ LANGUAGE="VBScript" %>
<% Option Explicit %>
<%
Const adOpenForwardOnly=0
Const adLockOptimistic=3
Const adLockPessimistic=2
Const adLockReadOnly=1
Const adCmdTable=2
Dim objConn
Dim objRS
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=fsamejimcom_mjs.dsn;uid=******;pwd=p****"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "studentInfo", objConn, , adLockOptimistic, adCmdTable
objRS.AddNew
objRS("familyID")="2"
objRS("studentName")="Sammy"
objRS("class")="4"
objRS.Update
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

==============================
By the way, I can view the data by the code below.
==============================
<%@ LANGUAGE="VBScript" %>
<% Option Explicit %>
<%
Const adOpenForwardOnly=0
Const adLockOptimistic=3
Const adLockPessimistic=2
Const adLockReadOnly=1
Const adCmdTable=2
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=fsamejimcom_mjs.dsn;uid=*******;pwd=******"
Dim objRS
Set objRS=Server.CreateObject("ADODB.Recordset")
objRS.Open "studentInfo", objConn, , , adCmdTable
Do While Not objRs.EOF
%>

<%= objRS.Fields("studentName").Value %></ br>
<%= objRS.Fields("id").Value %></ br>
<%= objRS.Fields("FamilyID").Value %></ br>
<%= objRS.Fields("class").Value %></ br>
<%
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

</blockquote id="quote"></font id="quote">

steurm
09-18-2003, 11:03 AM
Does this mean that you get an error ? If so, please give us information about that. Otherwise it is difficult to solve your problem

[b]quote:You should never be able to view the code</blockquote id="quote"></font id="quote">

Bruce, I don't think he means that he can see code, but that he can show the data in de database with the code he provided

--
Steurm
www.steurm.net/steurm

fsamejimcom
09-22-2003, 03:26 AM
Sorry for the confusion.
In fact, this code worked. I just needed to wait a little.
Sammy