<%@ Language=VBScript %>
<HTML>
<HEAD><TITLE>Update Product Information</TITLE></HEAD>
<%
Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & _
        "c:\Learn_ASP_Classic\Northwind.mdb"
set rst = Server.CreateObject("ADODB.Recordset")
If Len(Request.QueryString("ProductID")) <> 0 Then
    strSQL="SELECT * FROM Products WHERE ProductID="
    rst.Open(strSQL & Request.QueryString("ProductID")), conn, 0, 1
    If Not rst.EOF Then
        rst.MoveFirst
%>
<BODY>
<FORM ACTION="UpdateProduct.asp" METHOD="POST" id=form2 name=form2>
<Input Type=hidden Name=txtProductID Value="<% =rst("ProductID") %>">
<Input Type=hidden Name=txtProductName Value="<% =rst("ProductName") %>">

<CENTER><H4><% =rst("ProductName") %>
    &nbsp;(Product ID=<%=rst("ProductID")%>)</H></CENTER><P>
<TABLE BORDER=0 CELLSPACING=4 CELLPADDING=4>
    <TR>
        <TD WIDTH=200 COLSPAN="2"><FONT COLOR=Blue>Unit Price ($):</FONT></TD>
        <TD BGCOLOR="#00FF00">
        <INPUT TYPE="text" NAME="UnitPrice" VALUE="<% =rst("UnitPrice") %>"</TD>
    </TR>
    <TR>
        <TD COLSPAN="2"><FONT COLOR=Blue>Units In Stock:</FONT></TD>
        <TD BGCOLOR=#00FF00">
        <INPUT TYPE="text" NAME="UnitsInStock" VALUE="<%=rst("UnitsInStock") %>"</TD>
    </TR>
    <TR>
        <TD COLSPAN="2"></TD>
        <TD><INPUT type="submit" value="Update Data" id=submit2 name=submit2></TD>
    </TR>
</TABLE><HR>
</FORM>
<%
    End If
    rst.Close
End If
If Not IsEmpty(Request.Form("submit2")) Then
    If Request.Form("UnitPrice")= "" or _
        Request.Form("UnitsInStock") = "" Then
        Response.Write "<B><Font Color=Red>You cannot leave any fields blank." _
            & "Please Try Again</B></FONT>"
Else
    strSQL = "UPDATE Products SET " _
        & "UnitPrice = '" & Request.Form("UnitPrice")& "', " _
        & "UnitsInStock = '" & Request.Form("UnitsInStock")& "' " _
        & "WHERE ProductID = " & Request.Form("txtProductID")
    conn.Execute strSQL
    Response.Write "The following Update statement was executed for <B>" _
        & Request.Form("txtProductName") &"</B><BR>"
    Response.Write "<PRE>" & strSQL & "</PRE><BR>"
    End If
End If
    strSql = "SELECT * FROM [Products] ORDER BY [ProductName]"
    Set rst = conn.Execute (strSql)
    If Not rst.EOF Then
        rst.MoveFirst
%>
<FORM ACTION="UpdateProduct.asp" METHOD="Get" >
<TABLE>
<TR>
    <TD><B>Select a Product to Update</B></TD>
    <TD><SELECT Name="ProductID">
    <OPTION></OPTION>
<%
    Do While Not rst.EOF
    Response.Write "<OPTION Value='" & rst("ProductID") & "'> " & _
        rst("ProductName") & "</OPTION>"
    rst.MoveNext
    Loop
    End If
    rst.Close
    set rst = Nothing
    conn.Close
    set conn = Nothing
%>
<TD><INPUT type="submit" value="Retrieve Data" id=submit1 name=submit1></TD>
</SELECT></TD>
</TR>
</TABLE><HR>
</FORM></BODY>
</HTML>
