adding to db

Discussion in 'ASP General' started by mike, Jul 2, 2003.

  1. mike

    mike Guest

    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>
    mike, Jul 2, 2003
    #1
    1. Advertising

  2. mike

    Tom B Guest

    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>






    "mike" <> wrote in message
    news:03c101c340cc$d79c5a00$...
    > 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>
    Tom B, Jul 2, 2003
    #2
    1. Advertising

  3. mike

    Robb Meade Guest

    "mike" wrote ...

    > 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
    Robb Meade, Jul 2, 2003
    #3
  4. mike

    Bob Barrows Guest

    Bob Barrows, Jul 3, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul M.

    Adding to a list box in ASP .Net

    Paul M., Aug 16, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    6,717
    Paul M.
    Aug 22, 2003
  2. Curt Emich

    Adding VB.NET

    Curt Emich, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    Mary Chipman
    Dec 16, 2003
  3. Jonas L

    VS is adding code when compiling

    Jonas L, Apr 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,014
    =?iso-8859-15?Q?Lasse_V=E5gs=E6ther_Karlsen?=
    Apr 1, 2004
  4. news.microsoft.com
    Replies:
    0
    Views:
    377
    news.microsoft.com
    May 3, 2004
  5. =?Utf-8?B?UGF0cmljaw==?=

    Need help adding a chart in VB.NET

    =?Utf-8?B?UGF0cmljaw==?=, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    12,770
    ian_taylor
    Apr 18, 2008
Loading...

Share This Page