AddNew

Discussion in 'Databases' started by fsamejimcom, Sep 17, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. 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
    %>
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    Did you name the page with .asp extension?


    You should never be able to view the code

    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">
     
  3. Does this mean that you get an error ? If so, please give us information about that. Otherwise it is difficult to solve your problem

    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
     
  4. Sorry for the confusion.
    In fact, this code worked. I just needed to wait a little.
    Sammy
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page