CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Posts
    169

    Thumbs down adding records in database using vbscript in asp page

    Hi

    Ive some fields on asp page and i want to add records in my database by updating my form fields.
    how can i do that

    if u can provide some example that'll be great.

    thnx

  2. #2
    Join Date
    Nov 2004
    Posts
    13

    Re: adding records in database using vbscript in asp page

    Try this. All of this code is in one page. The form posts the fields to the same page, updates the database and then allows you to add another record.

    When you first come into the page there will be no value in the form field "CMD" so the processing is skipped

    <%
    'first check to see if there is a new record to add


    If request.form("cmd")="Add" then
    'create database connection

    set rs=Server.CreateObject("ADODB.Recordset")

    'open the database recordset
    rs.open "[your table]", "[your database connection string]", 3, 2, 2

    'create new record
    rs.addnew

    'set the values of the database fields from the submitted form
    rs("[yourField_1]")=request.form("[yourFormField_1]")
    rs("[yourField_n]")=request.form("[yourFormField_n]")

    'etc...

    'commit the record to the database
    rs.Update

    'close the recordset
    rs.close

    'destroy the database recordset object to conserve server resources
    set rs=Nothing
    End if


    %>
    <HTML>
    <HEAD>
    <!-- your head code goes here -->
    </head>

    <BODY>
    <FORM method=post action="[thisPageName].asp">
    <INPUT TYPE="HIDDEN" NAME="CMD" VALUE="ADD">
    <INPUT type = text name="[yourFormField_1]">
    <!--etc-->

    </FORM>
    </BODY>
    </HTML>

    If you omit the line
    rs.Addnew
    the current record (by default the first record in the recordset) will be updated.
    __________________
    Remote Control Cars at RC-Playtime.co.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured