直播中
[GuestBook]
book_id
UserName
Post_Time
Content
因?yàn)閷?duì)CSharp掌握還不好,寫得有點(diǎn)亂,其實(shí)很多地方可以寫得簡(jiǎn)單點(diǎn)。輸出數(shù)據(jù)時(shí)可以使用不同的方法,我是用了
服務(wù)器自帶的控件Repeater來輸出;還可以用getString的方法讀取數(shù)據(jù)。值得研究的地方還有很多哦,呵呵~
另外沒有對(duì)數(shù)據(jù)檢查,微軟的文檔上有說有一個(gè)服務(wù)器端的檢查控件,其實(shí)有好幾個(gè),很復(fù)雜,太多E文了,我還在
看,誰要是有使用經(jīng)驗(yàn)不妨教我一把。
順便說一聲,NGWS文檔里面的東西好多錯(cuò)誤,真見鬼! :(
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %>
<%@page responseencoding="gb2312" %>
<script language="C#" runat="server">
void Page_Load(Object semder, EventArgs e) {
SQLConnection myConnection = new SQLConnection
("server=sowen;uid=guestbook;pwd=guestbook;database=guestbook");
SQLDataReader myreader;
if (Request.QueryString["action"]=="del") {
String delCmd = "Delete From GuestBook Where book_id=" + Request.QueryString["book_id"];
SQLCommand myDelCommand = new SQLCommand(delCmd.ToString(),myConnection);
myDelCommand.ActiveConnection.Open();
myDelCommand.Execute(out myreader);
Message.InnerHtml = "<B>刪除留言!</B>";
myDelCommand.ActiveConnection.Close();
}
if (Request.Form["action"]=="save") {
String insertCmd = "Insert Into GuestBook(UserName,Post_time,Content) Values('" + Request.Form
["UserName"] + "','" + DateTime.Now + "','" + Request.Form["Content"] + "')";
SQLCommand myInsertCommand = new SQLCommand(insertCmd.ToString(),myConnection);
myInsertCommand.ActiveConnection.Open();
//int rowsAffected = 0;
myInsertCommand.Execute(out myreader);
Message.InnerHtml = "<B>留言成功!</B>";
myInsertCommand.ActiveConnection.Close();
}
SQLDataSetCommand myCommand = new SQLDataSetCommand("select * from GuestBook Order By post_time
DESC", myConnection);
DataSet ds = new DataSet();
myCommand.FillDataSet(ds, "UserName");
MyDataList.DataSource = ds.Tables["UserName"].DefaultView;
MyDataList.DataBind();
}
//Boolean Check_it(Object Sender) {
// if (Sender.Value=="") return False;
//}
</script>
<html>
<body>
<title>留言板</title>
<center>
<table>
<div id=Message runat=server></div>
<p><a href="guest.aspx">刷新</a></p>
<form action=guest.aspx method=post>
<tr><td>大名:</td><td><input type=text name=UserName size=10></td></tr>
<tr><td valign=top>留言:</td><td><textarea colspan=30 rows=4 name=content></textarea></td></tr>
<tr><td colspan=2><input type=submit value="保存"></td></tr>
<input type=hidden name=action value=save>
</table>
</form>
<table>
<ASP:Repeater id="MyDataList" runat="server">
<template name="itemtemplate">
<tr>
<td>大名:</td><td><%# DataBinder.Eval(Container.DataItem, "UserName") %> <a
href="guest.aspx?action=del&book_id=<%# DataBinder.Eval(Container.DataItem, "book_id") %>">刪除留言
</a></td>
</tr>
<tr>
<td>留言時(shí)間:</td><td><%# DataBinder.Eval(Container.DataItem, "Post_Time") %></td>
</tr>
<tr>
<tD>留言內(nèi)容:</td><td><%# DataBinder.Eval(Container.DataItem, "Content") %></td>
</tr>
<tr><td colspan=2 height=10></td></tr>
<tr><td colspan=2 height=1 bgcolor=black></td></tr>
<tr><td colspan=2 height=10></td></tr>
</template>
</ASP:Repeater>
</table>
</body></html>