从ASP迁移至ASP+--从用户那儿收集数据
从ASP迁移至ASP+--从用户那儿收集数据,从ASP迁移至ASP+--从用户那儿收集数据
一旦所有的输入都经过了验证,我们被导向cookie.aspx,通过该页将数据插如数据库,同时将用户登录。在signup.aspx中,一旦数据得到验证,我们将所有的表格值存入会话变量中,然后进行重定向:
< script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
If Page.IsPostBack And Page.IsValid Then
'Create the Session Variables froim the Form Fields
Session("strFName") = Request.Form("txtFirstName")
Session("strLName") = Request.Form("txtLastName")
Session("strAddress") = Request.Form("txtAddress")
Session("strCity") = Request.Form("txtCity")
Session("strState") = Request.Form("txtState")
Session("strZipcode") = Request.Form("txtZipcode")
Session("strEmail") = Request.Form("txtEmail")
Session("strPhone") = Request.Form("txtPhone")
Session("strUserName") = Request.Form("txtUserName")
Session("strPassword") = Request.Form("txtPassword")
Response.Redirect("cookie.aspx")
End If
.. . .
End Sub
< /script>
在cookie.aspx中,我们以会话变量的值做输入来创建一个ANSI-SQL语句。为了向数据库中添加值,我们利用ADOCommand对象。我们将SQL语句及ADOConnection对象传递给ADOCommand。设置了ADOCommand后,我们打开连接,调用ADOCommand.Execute:
< script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
Dim cnCon As New ADOConnection
Dim dcAdd As ADOCommand
Dim strSQL As String
strSQL = "INSERT INTO Students " & _
"(FirstName, LastName, Address, City, State, " & _
"Zipcode, Phone, Email, UserName, [Password] ) " & _
"VALUES (" & _
"'" & Session("strFName") & "', " & _
"'" & Session("strLName") & "', " & _
"'" & Session("strAddress") & "', " & _
"'" & Session("strCity") & "', " & _
"'" & Session("strState") & "', " & _
"'" & Session("strZipcode") & "', " & _
"'" & Session("strPhone") & "', " & _
"'" & Session("strEmail") & "', " & _
"'" & Session("strUserName") & "', " & _
"'" & Session("strPassword") & "'" & _
")"
cnCon = Connect.ConnectToDB()
dcAdd = New ADOCommand(strSQL, cnCon)
cnCon.Open()
dcAdd.Execute()
End Sub
< /script>
新的数据已经添加进了数据库,我们的新生也登录进来了。当学生报名参加一门课程时,类似的功能被用来向报名表插入Student_ID和Session_ID。
===总结===
尽管这只是对我们将一个小型ASP站点迁移至ASP+站点要面临的一些挑战的简要的概括,我们仍然涉及了一些主要的问题。其他一些要做的修改是很小的。当然,我