utilizzazione di un db

Form generalizzato e ricorsivo

' il Flag determina l'uso di questo Form ' vediamo se il Flag è passato da una Form, altrimenti lo inizializziamo If request("Flag") = "" then Flag = 0 Else Flag = request("Flag") End If ' facciamo cose diverse Select Case Flag Case 0 - compilazione Case 0 ' se il Form è chiamato senza valori, ' facciamolo riempire, mettiamo il Flag a 1 e lo richiamiamo %> AGGIUNTA DI UN NUOVO RECORD <form action="Form.asp" method="post"> Name: <input type="text" name="Name"> City: <input type="text" name="City"></td> <input type="hidden" name="Flag" value=1> <input type="submit" value="Submit"> <input type="button" value="Clear"></form> Case 1 - verifica Case 1 ' se il Form è stato riempito ' validiamo l'informazione, generiamo un messaggio di errore e riproponiamolo Validation = 0 If request.form("Name")="" then response.write "<font color='red'>" response.write "<b>You must enter a name.</font>" ' if the data isn't valid, increment Validation value Validation = Validation + 1 Else Name = request.form("Name") End If If request.form("City")="" then response.write "<font color='red'>" response.write "You must enter a City.</font>" Validation = Validation + 1 Else City = request.form("City") End If If Validation > 0 then ' riproponiamo il Form per la correzione response.write "<form>" response.write "<input type='button' value='Return to Form' onclick=history.go(-1)>" response.write "</form>" response.end Else ' riproponiamo il Form per la visualizzazione e il controllo response.write "Prego cerificare l'informazione:" For each name in request.form If name = "Flag" then response.write "&nbsp;" Else response.write Name response.write request.form(name) End If Next ' infine chiediamo conferma e richiamiamo questo setesso Form con Flag=2 response.write "<form method='post' action='Form.asp'>" For each name in request.form If Name="Flag" then response.write "<input type='hidden' name='" response.write Name & "' value=2>" Else response.write "<input type='hidden' name='" response.write Name & "' value='" & request.form(Name) response.write "'>" End If Next response.write "<input type='submit' value='Submit Information'>" response.write "<input type='button' value='Modify Information' onclick=history.go(-1)>" response.write "</form>" response.end End If Case 2 - inserimento Case 2 ' inserimento Name = request.form("Name") City = request.form("City") State = request.form("State") Country = request("Country") set conn = server.createobject("adodb.connection") conn.open "kathi" SQLstmt = "INSERT INTO Sample (Name,City,State,Country)" SQLstmt = SQLstmt & " VALUES (" SQLstmt = SQLstmt & "'" & Name & "'," SQLstmt = SQLstmt & "'" & City & "'," SQLstmt = SQLstmt & "'" & State & "'," SQLstmt = SQLstmt & "'" & Country & "'" SQLstmt = SQLstmt & ")" Set RS = conn.execute(SQLstmt) If err.number>0 then response.write "VBScript Errors Occured:" & "<P>" response.write "Error Number=" & err.number & "<P>" response.write "Error Descr.=" & err.description & "<P>" response.write "Help Context=" & err.helpcontext & "<P>" response.write "Help Path=" & err.helppath & "<P>" response.write "Native Error=" & err.nativeerror & "<P>" response.write "Source=" & err.source & "<P>" response.write "SQLState=" & err.sqlstate & "<P>" end if IF conn.errors.count> 0 then response.write "Database Errors Occured" & "<P>" response.write SQLstmt & "<P>" for counter= 0 to conn.errors.count response.write "Error #" & conn.errors(counter).number & "<P>" response.write "Error desc. -> " & conn.errors(counter).description & "<P>" next else response.write "<font face='arial'><b>" response.write "The record has been added.</b><p>" response.write "<a href='sample1.asp'>" response.write "View All Records</a></font>" end if Conn.Close set conn=nothing set rs = nothing End Select bello, vero?