How does one update all records displayed in a asp page

Discussion in 'ASP General' started by Jack, Jan 25, 2006.

  1. Jack

    Jack Guest

    Hi,
    I got a test asp page which connects to Northwind.mdb database. This page
    pulls all the rows from the Customers table. One column i.e. GoodStatus has
    been added to the customers table. The following is the code to display all
    records of the customers table with some customization.
    CODE:
    <%@ Language=VBScript %>
    <!-- #include file="adovbs.inc" -->
    <HTML>
    <BODY>

    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <title>Testing Multiple Records Save</title>

    <SCRIPT LANGUAGE="VBScript">


    sub btn_LogOut_OnClick()
    dim asnwer
    answer=msgbox("Are you sure you want to exit?.",vbYesNo,"Warning")
    if answer=vbyes then
    window.location.href = "http://localhost/beginaspdatabase1/"
    end if
    end sub

    sub btn_Save_OnClick()
    dim asnwer
    answer=msgbox("Are you sure you want to save your
    changes?",vbYesNo,"Warning")
    if answer=vbyes then
    window.location.href =
    "http://localhost/beginaspdatabase1/update_all_records.asp"
    end if
    end sub
    </SCRIPT>
    </HEAD>

    <%


    myDSN="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=C:\Northwind97\Northwind.mdb"

    set CN=server.createobject("ADODB.Connection")
    CN.Open myDSN

    set sRS=server.createobject("ADODB.Recordset")

    sRS.ActiveConnection = CN

    SQL = "SELECT EmployeeID, LastName, FirstName, Title, GoodStatus from
    Employees"
    'Response.Write SQL & "<br>"
    'Response.End
    sRS.Open SQL

    %>


    <div ALIGN="CENTER">
    <big><big><font COLOR="navy">Test Database Northwind</font></big></big>

    <H4>
    <font COLOR="red">Saving changes of all records at one time</font>
    </H4>
    </div>
    <div ALIGN="CENTER">


    <%
    Response.Write "<table border='1' width='50%' height='1' cellspacing='1' >"
    Response.Write "<th>ID</th><th>Last Name</th><th>First
    Name</th><th>Title</th><th>Good Status</th>"
    %>
    <%
    do until sRS.eof
    ID = sRS("EmployeeID")
    LastName = sRS("LastName")
    FirstName = sRS("FirstName")
    Title = sRS("Title")
    l_GoodStatus = sRS("GoodStatus")
    %>

    <tr>
    <td align='center' width = '5%'>
    <font color="#000000">
    <%Response.Write ID%></font>
    </td>


    <td align='center' width = '12%'>
    <font color="#000000">
    <%Response.Write LastName%>

    <td align='center' width = '12%' >
    <font color="#000000">
    <%Response.Write FirstName%>

    <td align='center' width = '10%'>
    <font color="#000000">
    <input type="text" name="txt_Title" size="33" value ="<%Response.Write
    (Title)%>" style="font-family: Times New Roman; font-size: 10pt"></font>
    </td>


    <%'Response.Write Title%>
    </td>

    <td align='center' width = '8%'>
    <font color="#000000">
    <input type="checkbox" name="chk_GoodStatus" value="ON" <%Response.write
    l_GoodStatus%><%if cbool(l_GoodStatus) then response.write " checked" else
    Response.write " unchecked"%>>
    </td>
    </tr>

    <%
    sRs.MoveNext
    loop
    sRS.Close
    Set sRS = Nothing
    %>

    </DIV>

    <input type="button" value="Log Out" name="btn_LogOut" >
    <input type="submit" value="Save" name="btn_Save">

    </BODY>
    </HTML>

    Now I need to change some values in the title and goodstatus field and save
    all the changes in whatever records made. This update has to be in asp page
    update_all_records.asp as pointed in the code above. I have no idea how to
    handle all the rows as in the present case. Any help or suggestion is
    appreciated. Thanks.
     
    Jack, Jan 25, 2006
    #1
    1. Advertising

  2. Jack

    Chi Guest

    Best bet is...
    1. Pass all the values in a form to SqlParameters (one value to one
    parameter)
    2. Then Create a stored procedure that uses these parameters.
    then you can update, insert, whatever it is you want to do.


    "Jack" <> wrote in message
    news:...
    > Hi,
    > I got a test asp page which connects to Northwind.mdb database. This page
    > pulls all the rows from the Customers table. One column i.e. GoodStatus
    > has
    > been added to the customers table. The following is the code to display
    > all
    > records of the customers table with some customization.
    > CODE:
    > <%@ Language=VBScript %>
    > <!-- #include file="adovbs.inc" -->
    > <HTML>
    > <BODY>
    >
    > <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    > <title>Testing Multiple Records Save</title>
    >
    > <SCRIPT LANGUAGE="VBScript">
    >
    >
    > sub btn_LogOut_OnClick()
    > dim asnwer
    > answer=msgbox("Are you sure you want to exit?.",vbYesNo,"Warning")
    > if answer=vbyes then
    > window.location.href = "http://localhost/beginaspdatabase1/"
    > end if
    > end sub
    >
    > sub btn_Save_OnClick()
    > dim asnwer
    > answer=msgbox("Are you sure you want to save your
    > changes?",vbYesNo,"Warning")
    > if answer=vbyes then
    > window.location.href =
    > "http://localhost/beginaspdatabase1/update_all_records.asp"
    > end if
    > end sub
    > </SCRIPT>
    > </HEAD>
    >
    > <%
    >
    >
    > myDSN="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=C:\Northwind97\Northwind.mdb"
    >
    > set CN=server.createobject("ADODB.Connection")
    > CN.Open myDSN
    >
    > set sRS=server.createobject("ADODB.Recordset")
    >
    > sRS.ActiveConnection = CN
    >
    > SQL = "SELECT EmployeeID, LastName, FirstName, Title, GoodStatus from
    > Employees"
    > 'Response.Write SQL & "<br>"
    > 'Response.End
    > sRS.Open SQL
    >
    > %>
    >
    >
    > <div ALIGN="CENTER">
    > <big><big><font COLOR="navy">Test Database Northwind</font></big></big>
    >
    > <H4>
    > <font COLOR="red">Saving changes of all records at one time</font>
    > </H4>
    > </div>
    > <div ALIGN="CENTER">
    >
    >
    > <%
    > Response.Write "<table border='1' width='50%' height='1' cellspacing='1'
    > >"

    > Response.Write "<th>ID</th><th>Last Name</th><th>First
    > Name</th><th>Title</th><th>Good Status</th>"
    > %>
    > <%
    > do until sRS.eof
    > ID = sRS("EmployeeID")
    > LastName = sRS("LastName")
    > FirstName = sRS("FirstName")
    > Title = sRS("Title")
    > l_GoodStatus = sRS("GoodStatus")
    > %>
    >
    > <tr>
    > <td align='center' width = '5%'>
    > <font color="#000000">
    > <%Response.Write ID%></font>
    > </td>
    >
    >
    > <td align='center' width = '12%'>
    > <font color="#000000">
    > <%Response.Write LastName%>
    >
    > <td align='center' width = '12%' >
    > <font color="#000000">
    > <%Response.Write FirstName%>
    >
    > <td align='center' width = '10%'>
    > <font color="#000000">
    > <input type="text" name="txt_Title" size="33" value ="<%Response.Write
    > (Title)%>" style="font-family: Times New Roman; font-size: 10pt"></font>
    > </td>
    >
    >
    > <%'Response.Write Title%>
    > </td>
    >
    > <td align='center' width = '8%'>
    > <font color="#000000">
    > <input type="checkbox" name="chk_GoodStatus" value="ON" <%Response.write
    > l_GoodStatus%><%if cbool(l_GoodStatus) then response.write " checked" else
    > Response.write " unchecked"%>>
    > </td>
    > </tr>
    >
    > <%
    > sRs.MoveNext
    > loop
    > sRS.Close
    > Set sRS = Nothing
    > %>
    >
    > </DIV>
    >
    > <input type="button" value="Log Out" name="btn_LogOut" >
    > <input type="submit" value="Save" name="btn_Save">
    >
    > </BODY>
    > </HTML>
    >
    > Now I need to change some values in the title and goodstatus field and
    > save
    > all the changes in whatever records made. This update has to be in asp
    > page
    > update_all_records.asp as pointed in the code above. I have no idea how to
    > handle all the rows as in the present case. Any help or suggestion is
    > appreciated. Thanks.
     
    Chi, Feb 1, 2006
    #2
    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. Edward
    Replies:
    1
    Views:
    326
    =?Utf-8?B?UmF2aW5kcmE=?=
    Jun 10, 2004
  2. misiek
    Replies:
    7
    Views:
    6,850
    misiek
    Feb 28, 2006
  3. boney
    Replies:
    1
    Views:
    580
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    474
    Ray at
    May 10, 2004
  5. Replies:
    3
    Views:
    679
    Anthony Jones
    Nov 2, 2006
Loading...

Share This Page