asp+版本简单的留言板的制作(二)

asp+版本简单的留言板的制作(二)
/*
豆腐制作,都是精品
http://www.asp888.net 豆腐技术站
如转载,请保留版权信息
*/

在留言的录入界面完成后,自然要准备做留言内容的录入了。这个其中一个很关键的地方就是如何将我们在config.web 的内容读取出来,我用了下面的几条语句
Dim Cfg as HashTable
Cfg = Context.GetConfig("appsettings")
Conn = New SQLConnection(cfg("Conn"))
这样就得到了我们在config.web 中设定的 连接串,程序如下

1@ Import Namespace="System.Data" 
1@ Import Namespace="System.Data.SQL" 
 1<script language="VB" runat="server">   
 2Sub Page_Load(Src As Object, E As EventArgs)   
 3  
 4Dim conn As SQLConnection   
 5Dim Cfg as HashTable   
 6Cfg = Context.GetConfig("appsettings")   
 7Conn = New SQLConnection(cfg("Conn"))   
 8dim strSQL as string   
 9dim strNickName as string   
10dim strMail as string   
11dim strTitle as string   
12dim strContent as string   
13dim strIPAddr as string   
14strNickName=replace(request.form("txtName"),"'","''")   
15strEmail=replace(request.form("txtMail"),"'","''")   
16strTitle=replace(request.form("txtTitle"),"'","''")   
17strContent=replace(request.form("txtContent"),"'","''")   
18strIPAddr=Request.ServerVariables ("REMOTE_ADDR") '用户IP地址   
19strSQL="insert into msgBoard(nickname,email,ipAddr,msgTime,msgTitle,msgContent)values("   
20strSQL=strSQL & "'" & strNickName & "','" & strEMail & "','" & strIPAddr & "',getdate(),'" & strTitle & "','" & strContent & "')"   
21response.write(strSQL)   
22Dim Cmd As SQLCommand   
23Cmd = New SQLCommand(strSQL,conn)   
24Cmd.ActiveConnection.Open()   
25Cmd.Execute()   
26Cmd.ActiveConnection.Close()   
27Response.Redirect("showmsg.aspx")   
28end sub   
29</script>

大家其实一看,就知道这段程序其实和asp的程序没有什么区别嘛,对了,跟着MS 的唯一的好处就是 他们在升级的时候总是对他们的以前的系统进行了很好的 兼容,除了因为引用了 ado.net 而使得数据库的操作 改变的比较多以外,其他的代码基本上都没有什么大的改变,糟糕 说道这里 就说错了一句话,不是没有什么大的改动,变化还是很大的,只不过对以前兼容了,我们这样的简单的应用,似乎也不会牵扯到什么复杂的改变的:)

Published At
Categories with Web编程
Tagged with
comments powered by Disqus