This might be to difficult to explain but I'm going to give it a try. I have a page to update some server information.
I'm trying to use the same code in order to avoid rebuilding a page from scratch. In my update, I only want one field to be able to be changed. We have a table called "Dropdownlist" that holds our options. During the update phase, the field is populated with the option we have listed in the table. We use these options to update another table.
If I choose a select * in my query, the page works fine but displays all fields, I only want to show two fields and give the option to change the server owner.
Code:
Code:
<%@ Language=VBScript%>
<% Option Explicit %>
<% Response.Buffer = True %>
<!-- #include file = "conn.asp" -->
<html>
<title>Update Server Owner</title>
<head>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
</head>
<%
Dim strComputer
strComputer = Request.QueryString("servername")
%>
<!--<meta http-equiv=refresh content='60; url=index.asp'>-->
<body bgcolor="WhiteSmoke">
<style type="text/css">
TD.content { BACKGROUND-COLOR: #ffffff }
.clsBodyText { FONT-WEIGHT: normal; FONT-SIZE: 8pt; FONT-FAMILY: Verdana; font-style: normal }
.clsFieldLabel {FONT-WEIGHT: bold; FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana; }
.clsLabelHeading{FONT-WEIGHT: bold;FONT-SIZE: 12pt;COLOR: black; FONT-FAMILY: Verdana;}
.linkroll { font-family:Arial; font-size:8pt; font-style:normal; font-weight:bold; letter-spacing:normal;
text-decoration:none; text-transform:none; color:#858BFD; }
A.linkroll:hover { font-weight:bold; color:black }</style>
<%
Dim intPass
intPass = Request("PASS")
' -- Take Action based on how you came into this page
Select Case Trim(intPass)
Case Trim("1")
' -- Repeat Visit, update the data
UpdateData
Case Else
' -- First Time Visit, display HTML Form
DisplayHTMLForm
End Select
' -- Make sure nothing else gets processed
Response.End
Sub DisplayHTMLForm()
Dim conn2, conn3, objConn2 , objConn3, objRS2, i, f, cfval, k, j
Dim objRS3
Set conn2 = Server.CreateObject("ADODB.Connection")
Set conn3 = Server.CreateObject("ADODB.Connection")
conn2.ConnectionString = sConnection2
conn3.ConnectionString = sConnection2
conn2.Open
conn3.Open
Set objRS2 = conn2.Execute("SELECT * FROM serverreview WHERE SERVER_NAME='" & strComputer &"'")
%>
*****I would like to change the "*" to server_name, server_owner********
<FORM ACTION="serverupdateowner.asp?servername=<%=strComputer%>" METHOD="POST">
<INPUT TYPE="hidden" NAME="PASS" VALUE="1">
<TABLE BORDER="1" CELLPADDING="3" CELLSPACING="2" WIDTH="100%" align="left">
<tr>
<td colspan="2" align="center" class="clsFieldLabel">
Update Record for <%=strComputer%><br><a class=clsBodyText>Change the Server Owner.</a></tr>
<%
objRS2.MoveFirst
' -- Output data
For i = 0 to objRS2.Fields.Count - 1
Response.write "<TR>"
Response.Write "<TH align='left' width='30'><a class=clsBodyText align='left'>" & objRS2.Fields(i).Name
' - output value as a textbox, except for ID field
cfval = objRS2.Fields(i)
If objRS2.Fields(i).Name = "SERVER_NAME" OR _
objRS2.Fields(i).Name = "Server_UPDATE" Then
' - output a text box
Response.Write "</a></TH><TD><INPUT TYPE=""TEXT"" " & _
" NAME=""" & _
objRS2.Fields(i).Name & _
""" VALUE=""" & objRS2.Fields(i) & _
""" SIZE=""60"" readonly class=clsBodyText style=background-color:#eeeeee ></TD>"
ElseIf objRS2.Fields(i).Name = "Status" OR _
objRS2.Fields(i).Name = "Server_Owner" OR _
objRS2.Fields(i).Name = "Virtual_Machine" Then
Set objRS3 = conn3.Execute("SELECT * FROM DropDownList WHERE STable='serverreview' AND SColumn='" & objRS2.Fields(i).Name & "'")
k = 0
Response.Write "*</a></TH align='left'><TD><select class=clsBodyText NAME=" & objRS2.Fields(i).Name & " >"
For j = 2 to objRS3.Fields.Count - 1
If LCase(objRS3.Fields(j)) = LCase(cfval) Then
Response.Write "<option selected=""selected"" VALUE='" & objRS3.Fields(j) & "' >" & objRS3.Fields(j) & "</option>"
k = 1
Else
If objRS3.Fields(j) <> "" Then
Response.Write "<option VALUE='" & objRS3.Fields(j) & "' >" & objRS3.Fields(j) & "</option>"
End If
End If
Next
If k = 0 Then
Response.Write "<option size=""40"" selected=""selected"" value="""">Please Select...</option>"
End If
Response.Write "</select></TD>"
objRS3.Close
Set ObjRS3 = Nothing
Else
' - output a text box
Response.Write "*</a><TD><INPUT TYPE=""TEXT"" " & _
" NAME=""" & _
objRS2.Fields(i).Name & _
""" VALUE=""" & objRS2.Fields(i) & _
""" SIZE=""60"" class=clsBodyText></TD>"
End If
Response.write "</TR>"
Next
objRS2.Close
Set objRS2 = Nothing
conn2.Close
Set conn2 = Nothing
%>
<TR><TD> </TD><TD><INPUT TYPE="SUBMIT" VALUE=" Update "></TD></TR>
</TABLE>
</FORM>
<%End Sub
Sub UpdateData()
Dim conn3, objConn3 , objRS3, objRS4, i
Set conn3 = Server.CreateObject("ADODB.Connection")
conn3.ConnectionString = sConnection2
dim Field(85)
conn3.Open
Set objRS3 = conn3.Execute("SELECT * FROM serverreview WHERE SERVER_NAME='" & strComputer &"'")
objRS4 = "UPDATE serverreview SET "
For i = 0 to objRS3.Fields.Count - 1
Field(i) = Request("" & objRS3.Fields(i).Name & "")
objRS4 = objRS4 + objRS3.Fields(i).Name + "='" + Field(i) +"'"
If i <> objRS3.Fields.Count - 1 Then
objRS4 = objRS4 + ","
end if
Next
objRS4 = objRS4 + " WHERE SERVER_NAME='" & strComputer & "'"
conn3.Execute(objRS4)
if err<>0 then
response.write("Record Not Updated")
else
response.write("" & strComputer & " was updated!")
end if
End Sub
objRS3.Close
Set objRS3 = Nothing
objConn4.Close
Set objConn4 = Nothing
objRS4.Close
Set objRS4 = Nothing
%>
</body>
</html>
Please let me know if more information is needed or if there just might be an easier way. Still trying to learn the basics of ASP, but I'm starting to get the hang of it.
Thanks.