- 浏览: 2435264 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
几个漂亮的Button的CSS -
sws354:
多表连接的方式效率更低,几百条数据就能看出效果。
MySQL随机取数据最高效率的方法 -
lsj111:
用java实现如何做
PHP中利用mysql进行访问统计的思路和实现代码 -
check-枫叶:
您好!我现在也在弄google Maps,现在可以把2点之间的 ...
Google Maps API用法教程 -
nothingtalk:
博主,您好。
“所以我们接下来要介绍除去Gideon Ehr ...
排列组合算法1:生成全部有序列b
作者:未知 请与本人联系
这是一个用asp.net写的论坛程序,虽然简单但可以运行。
这个程序的编程思想其实还是基本延续了asp的方式,如果让那只大鸟儿看见可能要嘘之以鼻。但实际上这种方式对于asp程序向asp.net的快速移植还是有用的。如果你对这种移植不屑那也没办法,这个贴子就算给asp.net刚入门的小虾们开开眼。
这个例子包含3部分
1)forum.aspx-论坛主页。
2)reply.aspx-当在论坛主页中点击一个贴子时调用,显示贴子详细内容。
3)postmessage.aspx-上贴时调用,将内容保存入数据库
数据库结构Table-newpost:ThistablewillcontaintheNewTopicpostedmessages
postid(primarykey)Theuniqueidforeachnewtopic.
nameThenameoftheauthorofthemessage.
emailE-mailaddressoftheauthor.
subjectSubjectofthemessage.
ipIPaddressoftheauthor.
dateDate/TimeofthePost
messageMessageposted.
repliesNumberofrepliestothepost(ifany)
viewsNumberoftimesthemessagehasbeenviewed.
Table-reply:ThistablewillcontaintheRepliesmadetothenewtopics.
replyid(primarykey)Theuniqueidforeachreply.
nameNameoftheauthor.
emailE-mailaddressoftheauthor.
subjectSubjectofthepost
ipIPoftheauthor.
dateDate/Timeofpost.
messageMessageposted.
postidpostidfromthe"newpost"tableforwhichthismessageisareply.
用asp.net写的论坛程序--论坛主页
1)forum.aspx:-Themainforumpage
<%@PageLanguage="C#"Debug="true"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System"%>
<html><head>
<title>WelcometoMyForum!</title>
<scriptlanguage="C#"runat="server">
//executethisscriptwhenthepageloads
voidPage_Load(ObjectSrc,EventArgsE)
{
//CalltheMethodtoDataBindtheDataGrid
Binding();
}
//ThisMethodConnectstotheDatabase,andDataBindstheDatabasetotheDataGrid
publicvoidBinding()
{
//Stringtoconnecttothedatabase,IfyourDatabaseisinsomeotherdirectorythenchangethepath
//TotheDatabasebelow
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath(".\\db\\board.mdb");
//MakeaConnectiontotheDatabase
ADOConnectionmyConn=newADOConnection(strConn);
//StringtoselectrecordsfromtheDatabase.newpostTable
//Ihaveused"ORDERBYpostidDESC"sinceIwanttoshowthelatestpostonthetop
//Ifyouremovethisclausethentheoldestmessagewillbeshownfirst
stringstrCom="SELECTpostid,subject,name,replies,views,dateFROMnewpostORDERBYpostidDESC";
//OpentheConnection,AlwaysremembertoOpentheconnectionbeforedoinganythingelse
myConn.Open();
DataSetmyDataSet=newDataSet();
//CreateaADODataSetCommandandaDataSet
ADODataSetCommandmyCommand=newADODataSetCommand(strCom,myConn);
//FilltheDataSet
myCommand.FillDataSet(myDataSet,"newpost");
//Connectionisclosed
myConn.Close();
//SettheDataViewoftheTable"newpost"containedintheDataSetfortheDataGrid
DataGrid1.DataSource=myDataSet.Tables["newpost"].DefaultView;
//DataBindtheDataGrid
DataGrid1.DataBind();
}
//ThismethodiscalledwhentheDataGridisPaged(i.e.whenyouchangefromPage1toPage2etc..)
publicvoidDataGrid_Updt(Objectsender,DataGridPageChangedEventArgse)
{
//CalltheMethodtoDatabind
Binding();
}
//ThisMethodiscalledwhentheformissubmittedtomakeanewPost
publicvoidSubmit_Click(Objectsender,EventArgse)
{
//proceedonlyifalltherequiredfieldsarefilled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
//GettheCurrentDateandTime
DateTimenow=DateTime.Now;
errmess.Text="";
//Iambuildingacustomquerywhichwillbeusedtocallthepostmessage.aspxpage.
//SinceitwillbeaquerywehavetoencodethequeryintoUTF8format.
//SoIgetallthefieldsfromtheformandencodethemintoUTF8format
stringreq="name="+System.Web.HttpUtility.UrlEncodeToString(name.Text,System.Text.Encoding.UTF8);
req+="&&email="+System.Web.HttpUtility.UrlEncodeToString(email.Text,System.Text.Encoding.UTF8);
req+="&&subject="+System.Web.HttpUtility.UrlEncodeToString(subject.Text,System.Text.Encoding.UTF8);
//GettheHostAddressoftheAuthor
req+="&&ip="+System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(),System.Text.Encoding.UTF8);
req+="&&date="+System.Web.HttpUtility.UrlEncodeToString(now.ToString(),System.Text.Encoding.UTF8);
req+="&&message="+System.Web.HttpUtility.UrlEncodeToString(message.Text,System.Text.Encoding.UTF8);
//A'yes'isusedbelowtotellthepostmessagepagethatthisisanewtopicpost
req+="&&newpost="+System.Web.HttpUtility.UrlEncodeToString("yes",System.Text.Encoding.UTF8);
//callthepostmessage.aspxpageandappendthequerytoit.
Page.Navigate("postmessage.aspx?"+req);
}
else
{
errmess.Text="FillinalltheRequiredFieldsbeforePosting!<br>";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet></head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<!--#IncludeFile="header.inc"-->
<center>
<asp:labelid="errmess"text=""style="COLOR:#ff0000"runat="server"/>
<asp:Labelclass=fodarktext="<fontcolor=#00000>WelcometoMyDiscussionForum</font>"runat=server/>
<br>
<br>
<formmethod="post"runat="server"ID=Form1>
<%--TheDataGridsettings.Itsveryinterestinghowmuchyoucanplaywithit--%>
<asp:DataGridid=DataGrid1runat="server"ForeColor="Black"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_Updt"PageSize="20"AllowPaging="True"width="80%"autogeneratecolumns="False">
<propertyname="PagerStyle">
<asp:DataGridPagerStyleBackColor="Coral"Mode="NumericPages">
</asp:DataGridPagerStyle>
</property>
<propertyname="AlternatingItemStyle">
<asp:TableItemStyleBorderColor="#FFC080"BackColor="#FF9966">
</asp:TableItemStyle>
</property>
<propertyname="FooterStyle">
<asp:TableItemStyleForeColor="White"BackColor="DarkOrange">
</asp:TableItemStyle>
</property>
<propertyname="ItemStyle">
<asp:TableItemStyleBackColor="Moccasin">
</asp:TableItemStyle>
</property>
<propertyname="HeaderStyle">
<asp:TableItemStyleFont-Bold="True"ForeColor="White"BackColor="Coral">
</asp:TableItemStyle>
</property>
<%--IamsettinguptheIndividualcolumnsmyselfusingTemplates--%>
<propertyname="Columns">
<%--Manipulatethesubjectentrysothatitcontainsalinktothereplypage--%>
<asp:TemplateColumnHeaderText="Subject"itemstyle-width=50%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"Text='<%#"<ahref=reply.aspx?postid="+DataBinder.Eval(Container,"DataItem.postid")+">"
+DataBinder.Eval(Container,"DataItem.subject")+"</a>"%>'ID=Label2></asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="AuthorName"itemstyle-width=20%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"Text='<%#DataBinder.Eval(Container,"DataItem.name")%>'ID=Label3></asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="Replies"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='<%#DataBinder.Eval(Container,"DataItem.replies")%>'ID=Label4>
</asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="Views"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='<%#DataBinder.Eval(Container,"DataItem.views")%>'ID=Label5>
</asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="DateofPost"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='
<%#DataBinder.Eval(Container,"DataItem.date").ToString().ToDateTime().ToShortDateString()%>'ID=Label6>
</asp:Label>
</template>
</asp:TemplateColumn>
</property>
</asp:DataGrid>
<br>
<br>
<asp:Labelclass=fodarktext="<fontcolor=#00000>PostNewTopic</font>"runat=server/>
<br>
<tableborder="0"width="80%"align="center">
<tr>
<tdclass="fohead"colspan=2><b>PostNewTopic</b></td>
</tr>
<trclass="folight">
<td>Name:</td>
<td><asp:textboxtext=""id="name"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:textboxtext=""id="email"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:textboxtest=""id="subject"width=200runat="server"/><fontcolor=#ff0000>*</font>
</td></tr>
<trclass="folight">
<td>Message:</td>
<td>
<asp:TextBoxid=messagerunat="server"
Columns="30"Rows="15"TextMode="MultiLine"></asp:TextBox></td>
</tr>
<trclass=folight>
<tdcolspan=2>
<asp:Buttonclass=fodarkid=writeonClick=Submit_Clickrunat="server"Text="Submit"></asp:Button></td></tr>
</table>
</form>
</center>
<!--#IncludeFile="footer.inc"-->
</body></html>
用asp.net写的论坛程序--浏览贴子内容及回复
2)reply.aspx:Thetopicviewingandreplyingpage
<%@PageLanguage="C#"EnableSessionState="False"Debug="True"%>
<%@ImportNamespace="System"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<html><head>
<title>PostNewTopic.</title>
<%--Thesearetheimportedassembliesandnamespacesneeded--%>
<scriptLanguage="C#"runat="server">
DataSetds,rs;
DataRowdr;
stringpostid;
publicvoidPage_Load(objectsender,EventArgse)
{
//CheckifthepageisPostBack
if(!Page.IsPostBack)
{
//GetthepostidfromtheQuerystring
postid=Request.Params["postid"];
if(postid!=null)
{
//Databaseconnectionstring.Changethepathtothedatabasefileifyouhavesomeotherpathwhere
//youaresavingyourDatabasefile
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath(".\\db\\board.mdb");
//MakeaconnectiontotheDatabase
ADOConnectionmyConn=newADOConnection(strConn);
//stringtoselecttherecordsfromthenewposttable
stringstrCon="SELECTsubject,name,email,message,dateFROMnewpostWHEREpostid="+postid;
//setaADODataSetCommand
ADODataSetCommandmyCommand=newADODataSetCommand(strCon,myConn);
ds=newDataSet();
//Don'teverforgettoopentheConnection
myConn.Open();
//FilltheDataSet
myCommand.FillDataSet(ds,"newpost");
//GettheRowatposition'0'andstoreitinaDataRowobject
//Whyrowatposition'0'?Sincetherecanonlybeonerecordwiththegivenpostidremember!!
//WhyputintoaDataRow?ItseasytoaccessdatafromaDataRow
dr=ds.Tables["newpost"].Rows[0];
//Getthe"subject"fromtheDataRowandsetitupinthepostreplyform'ssubjectfield
subject.Text="Re:"+dr["subject"].ToString();
//Selecttherepliestothepostfromthereplytable
strCon="SELECTname,email,subject,message,dateFROMreplyWHEREpostid="+postid;
//MakeanewADODataSetCommandandDataSetforthereplytable
ADODataSetCommandmyCommand2=newADODataSetCommand(strCon,myConn);
rs=newDataSet();
//filltheDataSet
myCommand2.FillDataSet(rs,"reply");
//Codetoupdatethe"views"fieldforthenewpostTable
//Selecttheviewsfieldfromthetableforagivenpostid
strCon="SELECTviewsFROMnewpostWHEREpostid="+postid;
//MakeaADOCommandheresincewewantaADODataReaderlater
ADOCommandvicomm=newADOCommand(strCon,myConn);
ADODataReaderreader;
//executethestatementandcreateaADODataReader
vicomm.Execute(outreader);
//ReadtheFirstrecord(therecanonlybeonerecordremember!)
reader.Read();
//Geta"Int32"valuefromthefirstColumn(wehaveonecolumninthereader,checktheselectstatementabove)
inti=reader.GetInt32(0);
//Increasetheviewscount
i++;
reader.Close();
//Updatethenewposttablewiththenewviewsvalue
strCon="UPDATEnewpostSETviews="+i+"WHERE(postid="+postid+")";
//sinceweareusingthesameADOCOmmandobjectforthisstatementtootosettheCommandTextproperty
vicomm.CommandText=strCon;
//Sincethisstatementwillresultinnooutputweuse"ExecuteNonQuery()"method
vicomm.ExecuteNonQuery();
//closetheconnection
myConn.Close();
}
}
}
//Thismethodiscalledwhenthesubmitbuttonisclicked
publicvoidSubmit_Click(Objectsender,EventArgse)
{
//Getthepostid
postid=Request.Params["postid"];
//proceedonlyifalltherequiredfieldsarefilled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
DateTimenow=DateTime.Now;
errmess.Text="";
//Wehavetocallthepostmessage.aspxpagewithaquerytopostthedatatotheDatabase.
//HencewehavetofirstbuildthecustomqueryfromtheDatapostedbytheuser
//alsosinceweareusingaquerywehavetoencodethedataintoUTF8format
stringreq="name="+System.Web.HttpUtility.UrlEncodeToString(name.Text,System.Text.Encoding.UTF8);
req+="&&email="+System.Web.HttpUtility.UrlEncodeToString(email.Text,System.Text.Encoding.UTF8);
req+="&&subject="+System.Web.HttpUtility.UrlEncodeToString(subject.Text,System.Text.Encoding.UTF8);
req+="&&ip="+System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(),System.Text.Encoding.UTF8);
req+="&&date="+System.Web.HttpUtility.UrlEncodeToString(now.ToString(),System.Text.Encoding.UTF8);
req+="&&message="+System.Web.HttpUtility.UrlEncodeToString(message.Text,System.Text.Encoding.UTF8);
//Encode"no"toindicatethatthepostisnotanewpostbutitsareplytoaearliermessage
req+="&&newpost="+System.Web.HttpUtility.UrlEncodeToString("no",System.Text.Encoding.UTF8);
req+="&&previd="+System.Web.HttpUtility.UrlEncodeToString(postid,System.Text.Encoding.UTF8);
//Callthepostmessagepagewithourcustomquery
Page.Navigate("postmessage.aspx?"+req);
}
else
{
errmess.Text="FillinalltheRequiredFields!";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet></head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<%--Includeaheaderfile'header.inc'--%>
<!--#IncludeFile="header.inc"-->
<br>
<divalign=center>
<tableborder=0width=80%cellspacing=2>
<trclass=fohead><thwidth=20%>AuthorName</th>
<thwidth=80%>Message</th></tr>
<%--BelowIamencapsulatingtheemailoftheauthoroverthenameoftheauthor
sothatwhenyouclickontheauthorae-mailgetssenttohim
AlsoIamgetingtheDateTimefromtheDataBaseandDisplayingtheDateandTimeseparately--%>
<trclass=folight><tdrowspan=2align="center"><%="<ahref=mailto:"+dr["email"]+">"+dr["name"]+"</a>"%><br>
<fontsize=1><%=dr["date"].ToString().ToDateTime().ToShortDateString()%><br>
<%=dr["date"].ToString().ToDateTime().ToShortTimeString()%></font>
</td>
<td><b>Subject:</b><%=dr["subject"]%></td></tr>
<trclass=folight>
<td><pre><%=dr["message"]%></pre></td>
</tr>
<%--GetalltherepliestotheOriginalpostandshowthem--%>
<%intno=rs.Tables["reply"].Rows.Count;
if(no>0)
{
for(intj=0;j<no;j++)
{
DataRowrd=rs.Tables["reply"].Rows[j];
%>
<trclass=fodark>
<tdalign="center"><%="<ahref=mailto:"+rd["email"]+">"+rd["name"]+"</a>"%><br>
<fontsize=1><%=rd["date"].ToString().ToDateTime().ToShortDateString()%><br>
<%=rd["date"].ToString().ToDateTime().ToShortTimeString()%></font>
</td>
<td><pre><%=rd["message"]%></pre></td>
</tr>
<%
}
}
%>
</table>
</div>
<h3align="center"class="fodark"><ahref=forum.aspx>ClickHere</a>togotobacktoForum.
<br>ReplytotheAbovePost.</h3>
<br>
<asp:labelid="errmess"text=""style="COLOR:#ff0000"runat="server"/>
<formrunat="server">
<tableborder="0"width="80%"align="center">
<tr>
<tdclass="fohead"colspan=2><b>ReplytothePost</b></td>
</tr>
<trclass="folight">
<td>Name:</td>
<td><asp:textboxtext=""id="name"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:textboxtext=""id="email"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:textboxtest=""id="subject"width=200runat="server"/><fontcolor=#ff0000>*</font>
</td></tr>
<trclass="folight">
<td>Message:</td>
<td>
<asp:TextBoxid=messagerunat="server"
Columns="30"Rows="15"TextMode="MultiLine"></asp:TextBox></td>
</tr>
<trclass=folight>
<tdcolspan=2>
<asp:Buttonclass=fodarkid=writeonClick=Submit_Clickrunat="server"Text="Submit"></asp:Button></td></tr>
</table>
</form><br>
<br><!--#IncludeFile="footer.inc"-->
</body></html>
用asp.net写的论坛程序--上贴保存
3)postmessage.aspx:-ThepagewhichsaveddatatotheDatabase
<%@ImportNamespace="System"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<%@PageLanguage="C#"Debug="true"%>
<html>
<head>
<title>ThankYouforPosting!</title>
<scriptlanguage="C#"runat="server">
//executethisscriptwhenthepageloads
voidPage_Load(ObjectSrc,EventArgsE)
{
//ifthepageiscalledfromanotherpage
if(!Page.IsPostBack){
//GetalltheParametersfromtheQuerystring
stringname=Request.Params["name"];
stringemail=Request.Params["email"];
stringsubject=Request.Params["subject"];
stringip=Request.Params["ip"];
stringdate=Request.Params["date"];
stringmessage=Request.Params["message"];
boolnewmess=true;
stringprevid="1";
//CheckifthepostisaNewtopicorareplytoanewtopic
if(Request.Params["newpost"].Equals("no"))
{
//ifitsareplythengetthepostidcalledasprevidhere
newmess=false;
previd=Request.Params["previd"];
}
//Ifthepostisanewtopicthenfollowthebelowroutine
if(newmess)
{
//Thestringforthepathtothedatabase,ifyourdatabaseisinsomeother
directorytheneditthepath
//ofthisvariable
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=
"+Server.MapPath(".\\db\\board.mdb");
//GetaADOConnectiontothedatabase
ADOConnectionmyConn=newADOConnection(strConn);
//TheSQLSelectstatement
stringstrCom="Selectpostidfromnewpost";
//CreateaADOCommandsincewewantaADODataReaderlater
ADOCommandmyCommand=newADOCommand(strCom,myConn);
//Opentheconnection
myConn.Open();
ADODataReaderreader;
//ExecutethecommandandgettheDatainto"reader"
myCommand.Execute(outreader);
inti=1;
//Getthecurrentnumberofrecordspresentinthedatabase.
while(reader.Read())
{
i++;
}
reader.Close();
//buildtheSQLstatementtoinsertintotheDatabase
stringinsertStr="INSERTINTOnewpostVALUES("
+i+",'"
+name+"','"
+email+"','"
+subject+"','"
+ip+"','"
+date+"','"
+message+"',0,0)";
myCommand.CommandText=insertStr;
//SincetheSQLstatementdoesnotreturnanyoutputuse"ExecuteNonQuery()method
myCommand.ExecuteNonQuery();
//Closetheconnection
myConn.Close();
}
else
{
//Iftheposteddataisareplytoatopicthenfollowthebelowprocedure
//stringforthepathtothedatabase,ifyourdatabaseisstoredinsomeotherdirectorythen
//editthepathhere
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+
Server.MapPath(".\\db\\board.mdb");
ADOConnectionmyConn=newADOConnection(strConn);
//SQLstatementtoselectthereplyid
stringstrCom="Selectreplyidfromreply";
//createaADOCommand
ADOCommandmyCommand=newADOCommand(strCom,myConn);
//OpentheConnection
myConn.Open();
ADODataReaderreader;
//ExecutethecommandandgettheDatainto"reader"
myCommand.Execute(outreader);
inti=1;
//Getthecurrentnumberofrecordspresentinthedatabase.
while(reader.Read())
{
i++;
}
reader.Close();
//Buildastatementtoinsertthevaluesintothereplytable
stringinsertStr="INSERTINTOreplyVALUES("
+i+",'"
+name+"','"
+email+"','"
+subject+"','"
+ip+"','"
+date+"','"
+message+"',"
+previd+")";
myCommand.CommandText=insertStr;
//ExecuteNonQuery-sincethecommanddoesnotreturnanything
myCommand.ExecuteNonQuery();
//stringtogettherepliescolumnfromthenewposttable
stringreplyno="SELECTrepliesFROMnewpostWHEREpostid="+previd;
myCommand.CommandText=replyno;
//Executecommandandgetthereader
myCommand.Execute(outreader);
//readthefirstrecord(remembertherecanonlybeonerecordinthereadersincepostidisunique)
reader.Read();
//Getthe"Int16"valueofthenumberofrepliesfromtherepliescolumninthenewposttable
intrep=reader.GetInt16(0);
reader.Close();
rep++;
//SQLstatementtoupdatetherepliesfieldinthenewposttable
stringupdtStr="UPDATEnewpostSETreplies="+rep
+"WHERE(postid="+previd+")";
myCommand.CommandText=updtStr;
//ExecuteNonQuerrywhy??IguessUshouldknowbynow!
myCommand.ExecuteNonQuery();
myConn.Close();
}
//getthedifferentParametersfromthequerystringandstoreit
//torespectiveLabels
NameLabel.Text=name;
EmailLabel.Text=email;
SubjectLabel.Text=subject;
MessageLabel.Text=message;
}
else
{
//elsedisplayanerror
errmess.Text="ThisPageCannotbecalleddirectly.IthastobecalledfromtheFormpostingpage.<br>";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet>
</head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<!--#IncludeFile="header.inc"-->
<center>
<asp:labelid="errmess"text=""style="color:#FF0000"runat="server"/>
<h2class="fodark"><b>ThankYou,forpostingontheMessageBoard.</b></h2>
<tablealign=centerwidth="60%"border="0"cellspacing="2"cellpadding="1">
<trclass="fohead"><tdcolspan="2">TheinformationYouPosted!</td></tr>
<trclass="folight">
<td>Name:</td>
<td><asp:labelid="NameLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:labelid="EmailLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:labelid="SubjectLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>Message:</td>
<td><asp:labelid="MessageLabel"text=""runat="server"/></td>
</tr>
</table>
<br>
<h4class="fodark"><ahref="forum.aspx">Clickhere</a>togobacktotheForum.<br>
<%--Alittleworktoshowthelinktoreturnbacktothepageif,thepostwasareply--%>
<%if(Request.Params["previd"]!=null)
{%>
<ahref='reply.aspx?postid=<%=Request.Params["previd"]%>'>Clickhere</a>togoback
whereyoucamefrom.
<%}%>
</h4>
</center>
<!--#IncludeFile="footer.inc"-->
</body>
</html>
这是一个用asp.net写的论坛程序,虽然简单但可以运行。
这个程序的编程思想其实还是基本延续了asp的方式,如果让那只大鸟儿看见可能要嘘之以鼻。但实际上这种方式对于asp程序向asp.net的快速移植还是有用的。如果你对这种移植不屑那也没办法,这个贴子就算给asp.net刚入门的小虾们开开眼。
这个例子包含3部分
1)forum.aspx-论坛主页。
2)reply.aspx-当在论坛主页中点击一个贴子时调用,显示贴子详细内容。
3)postmessage.aspx-上贴时调用,将内容保存入数据库
数据库结构Table-newpost:ThistablewillcontaintheNewTopicpostedmessages
postid(primarykey)Theuniqueidforeachnewtopic.
nameThenameoftheauthorofthemessage.
emailE-mailaddressoftheauthor.
subjectSubjectofthemessage.
ipIPaddressoftheauthor.
dateDate/TimeofthePost
messageMessageposted.
repliesNumberofrepliestothepost(ifany)
viewsNumberoftimesthemessagehasbeenviewed.
Table-reply:ThistablewillcontaintheRepliesmadetothenewtopics.
replyid(primarykey)Theuniqueidforeachreply.
nameNameoftheauthor.
emailE-mailaddressoftheauthor.
subjectSubjectofthepost
ipIPoftheauthor.
dateDate/Timeofpost.
messageMessageposted.
postidpostidfromthe"newpost"tableforwhichthismessageisareply.
用asp.net写的论坛程序--论坛主页
1)forum.aspx:-Themainforumpage
<%@PageLanguage="C#"Debug="true"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System"%>
<html><head>
<title>WelcometoMyForum!</title>
<scriptlanguage="C#"runat="server">
//executethisscriptwhenthepageloads
voidPage_Load(ObjectSrc,EventArgsE)
{
//CalltheMethodtoDataBindtheDataGrid
Binding();
}
//ThisMethodConnectstotheDatabase,andDataBindstheDatabasetotheDataGrid
publicvoidBinding()
{
//Stringtoconnecttothedatabase,IfyourDatabaseisinsomeotherdirectorythenchangethepath
//TotheDatabasebelow
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath(".\\db\\board.mdb");
//MakeaConnectiontotheDatabase
ADOConnectionmyConn=newADOConnection(strConn);
//StringtoselectrecordsfromtheDatabase.newpostTable
//Ihaveused"ORDERBYpostidDESC"sinceIwanttoshowthelatestpostonthetop
//Ifyouremovethisclausethentheoldestmessagewillbeshownfirst
stringstrCom="SELECTpostid,subject,name,replies,views,dateFROMnewpostORDERBYpostidDESC";
//OpentheConnection,AlwaysremembertoOpentheconnectionbeforedoinganythingelse
myConn.Open();
DataSetmyDataSet=newDataSet();
//CreateaADODataSetCommandandaDataSet
ADODataSetCommandmyCommand=newADODataSetCommand(strCom,myConn);
//FilltheDataSet
myCommand.FillDataSet(myDataSet,"newpost");
//Connectionisclosed
myConn.Close();
//SettheDataViewoftheTable"newpost"containedintheDataSetfortheDataGrid
DataGrid1.DataSource=myDataSet.Tables["newpost"].DefaultView;
//DataBindtheDataGrid
DataGrid1.DataBind();
}
//ThismethodiscalledwhentheDataGridisPaged(i.e.whenyouchangefromPage1toPage2etc..)
publicvoidDataGrid_Updt(Objectsender,DataGridPageChangedEventArgse)
{
//CalltheMethodtoDatabind
Binding();
}
//ThisMethodiscalledwhentheformissubmittedtomakeanewPost
publicvoidSubmit_Click(Objectsender,EventArgse)
{
//proceedonlyifalltherequiredfieldsarefilled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
//GettheCurrentDateandTime
DateTimenow=DateTime.Now;
errmess.Text="";
//Iambuildingacustomquerywhichwillbeusedtocallthepostmessage.aspxpage.
//SinceitwillbeaquerywehavetoencodethequeryintoUTF8format.
//SoIgetallthefieldsfromtheformandencodethemintoUTF8format
stringreq="name="+System.Web.HttpUtility.UrlEncodeToString(name.Text,System.Text.Encoding.UTF8);
req+="&&email="+System.Web.HttpUtility.UrlEncodeToString(email.Text,System.Text.Encoding.UTF8);
req+="&&subject="+System.Web.HttpUtility.UrlEncodeToString(subject.Text,System.Text.Encoding.UTF8);
//GettheHostAddressoftheAuthor
req+="&&ip="+System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(),System.Text.Encoding.UTF8);
req+="&&date="+System.Web.HttpUtility.UrlEncodeToString(now.ToString(),System.Text.Encoding.UTF8);
req+="&&message="+System.Web.HttpUtility.UrlEncodeToString(message.Text,System.Text.Encoding.UTF8);
//A'yes'isusedbelowtotellthepostmessagepagethatthisisanewtopicpost
req+="&&newpost="+System.Web.HttpUtility.UrlEncodeToString("yes",System.Text.Encoding.UTF8);
//callthepostmessage.aspxpageandappendthequerytoit.
Page.Navigate("postmessage.aspx?"+req);
}
else
{
errmess.Text="FillinalltheRequiredFieldsbeforePosting!<br>";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet></head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<!--#IncludeFile="header.inc"-->
<center>
<asp:labelid="errmess"text=""style="COLOR:#ff0000"runat="server"/>
<asp:Labelclass=fodarktext="<fontcolor=#00000>WelcometoMyDiscussionForum</font>"runat=server/>
<br>
<br>
<formmethod="post"runat="server"ID=Form1>
<%--TheDataGridsettings.Itsveryinterestinghowmuchyoucanplaywithit--%>
<asp:DataGridid=DataGrid1runat="server"ForeColor="Black"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_Updt"PageSize="20"AllowPaging="True"width="80%"autogeneratecolumns="False">
<propertyname="PagerStyle">
<asp:DataGridPagerStyleBackColor="Coral"Mode="NumericPages">
</asp:DataGridPagerStyle>
</property>
<propertyname="AlternatingItemStyle">
<asp:TableItemStyleBorderColor="#FFC080"BackColor="#FF9966">
</asp:TableItemStyle>
</property>
<propertyname="FooterStyle">
<asp:TableItemStyleForeColor="White"BackColor="DarkOrange">
</asp:TableItemStyle>
</property>
<propertyname="ItemStyle">
<asp:TableItemStyleBackColor="Moccasin">
</asp:TableItemStyle>
</property>
<propertyname="HeaderStyle">
<asp:TableItemStyleFont-Bold="True"ForeColor="White"BackColor="Coral">
</asp:TableItemStyle>
</property>
<%--IamsettinguptheIndividualcolumnsmyselfusingTemplates--%>
<propertyname="Columns">
<%--Manipulatethesubjectentrysothatitcontainsalinktothereplypage--%>
<asp:TemplateColumnHeaderText="Subject"itemstyle-width=50%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"Text='<%#"<ahref=reply.aspx?postid="+DataBinder.Eval(Container,"DataItem.postid")+">"
+DataBinder.Eval(Container,"DataItem.subject")+"</a>"%>'ID=Label2></asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="AuthorName"itemstyle-width=20%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"Text='<%#DataBinder.Eval(Container,"DataItem.name")%>'ID=Label3></asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="Replies"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='<%#DataBinder.Eval(Container,"DataItem.replies")%>'ID=Label4>
</asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="Views"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='<%#DataBinder.Eval(Container,"DataItem.views")%>'ID=Label5>
</asp:Label>
</template>
</asp:TemplateColumn>
<asp:TemplateColumnHeaderText="DateofPost"itemstyle-width=10%>
<templatename="ItemTemplate">
<asp:Labelrunat="server"width=10%Text='
<%#DataBinder.Eval(Container,"DataItem.date").ToString().ToDateTime().ToShortDateString()%>'ID=Label6>
</asp:Label>
</template>
</asp:TemplateColumn>
</property>
</asp:DataGrid>
<br>
<br>
<asp:Labelclass=fodarktext="<fontcolor=#00000>PostNewTopic</font>"runat=server/>
<br>
<tableborder="0"width="80%"align="center">
<tr>
<tdclass="fohead"colspan=2><b>PostNewTopic</b></td>
</tr>
<trclass="folight">
<td>Name:</td>
<td><asp:textboxtext=""id="name"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:textboxtext=""id="email"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:textboxtest=""id="subject"width=200runat="server"/><fontcolor=#ff0000>*</font>
</td></tr>
<trclass="folight">
<td>Message:</td>
<td>
<asp:TextBoxid=messagerunat="server"
Columns="30"Rows="15"TextMode="MultiLine"></asp:TextBox></td>
</tr>
<trclass=folight>
<tdcolspan=2>
<asp:Buttonclass=fodarkid=writeonClick=Submit_Clickrunat="server"Text="Submit"></asp:Button></td></tr>
</table>
</form>
</center>
<!--#IncludeFile="footer.inc"-->
</body></html>
用asp.net写的论坛程序--浏览贴子内容及回复
2)reply.aspx:Thetopicviewingandreplyingpage
<%@PageLanguage="C#"EnableSessionState="False"Debug="True"%>
<%@ImportNamespace="System"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<html><head>
<title>PostNewTopic.</title>
<%--Thesearetheimportedassembliesandnamespacesneeded--%>
<scriptLanguage="C#"runat="server">
DataSetds,rs;
DataRowdr;
stringpostid;
publicvoidPage_Load(objectsender,EventArgse)
{
//CheckifthepageisPostBack
if(!Page.IsPostBack)
{
//GetthepostidfromtheQuerystring
postid=Request.Params["postid"];
if(postid!=null)
{
//Databaseconnectionstring.Changethepathtothedatabasefileifyouhavesomeotherpathwhere
//youaresavingyourDatabasefile
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+Server.MapPath(".\\db\\board.mdb");
//MakeaconnectiontotheDatabase
ADOConnectionmyConn=newADOConnection(strConn);
//stringtoselecttherecordsfromthenewposttable
stringstrCon="SELECTsubject,name,email,message,dateFROMnewpostWHEREpostid="+postid;
//setaADODataSetCommand
ADODataSetCommandmyCommand=newADODataSetCommand(strCon,myConn);
ds=newDataSet();
//Don'teverforgettoopentheConnection
myConn.Open();
//FilltheDataSet
myCommand.FillDataSet(ds,"newpost");
//GettheRowatposition'0'andstoreitinaDataRowobject
//Whyrowatposition'0'?Sincetherecanonlybeonerecordwiththegivenpostidremember!!
//WhyputintoaDataRow?ItseasytoaccessdatafromaDataRow
dr=ds.Tables["newpost"].Rows[0];
//Getthe"subject"fromtheDataRowandsetitupinthepostreplyform'ssubjectfield
subject.Text="Re:"+dr["subject"].ToString();
//Selecttherepliestothepostfromthereplytable
strCon="SELECTname,email,subject,message,dateFROMreplyWHEREpostid="+postid;
//MakeanewADODataSetCommandandDataSetforthereplytable
ADODataSetCommandmyCommand2=newADODataSetCommand(strCon,myConn);
rs=newDataSet();
//filltheDataSet
myCommand2.FillDataSet(rs,"reply");
//Codetoupdatethe"views"fieldforthenewpostTable
//Selecttheviewsfieldfromthetableforagivenpostid
strCon="SELECTviewsFROMnewpostWHEREpostid="+postid;
//MakeaADOCommandheresincewewantaADODataReaderlater
ADOCommandvicomm=newADOCommand(strCon,myConn);
ADODataReaderreader;
//executethestatementandcreateaADODataReader
vicomm.Execute(outreader);
//ReadtheFirstrecord(therecanonlybeonerecordremember!)
reader.Read();
//Geta"Int32"valuefromthefirstColumn(wehaveonecolumninthereader,checktheselectstatementabove)
inti=reader.GetInt32(0);
//Increasetheviewscount
i++;
reader.Close();
//Updatethenewposttablewiththenewviewsvalue
strCon="UPDATEnewpostSETviews="+i+"WHERE(postid="+postid+")";
//sinceweareusingthesameADOCOmmandobjectforthisstatementtootosettheCommandTextproperty
vicomm.CommandText=strCon;
//Sincethisstatementwillresultinnooutputweuse"ExecuteNonQuery()"method
vicomm.ExecuteNonQuery();
//closetheconnection
myConn.Close();
}
}
}
//Thismethodiscalledwhenthesubmitbuttonisclicked
publicvoidSubmit_Click(Objectsender,EventArgse)
{
//Getthepostid
postid=Request.Params["postid"];
//proceedonlyifalltherequiredfieldsarefilled-in
if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
DateTimenow=DateTime.Now;
errmess.Text="";
//Wehavetocallthepostmessage.aspxpagewithaquerytopostthedatatotheDatabase.
//HencewehavetofirstbuildthecustomqueryfromtheDatapostedbytheuser
//alsosinceweareusingaquerywehavetoencodethedataintoUTF8format
stringreq="name="+System.Web.HttpUtility.UrlEncodeToString(name.Text,System.Text.Encoding.UTF8);
req+="&&email="+System.Web.HttpUtility.UrlEncodeToString(email.Text,System.Text.Encoding.UTF8);
req+="&&subject="+System.Web.HttpUtility.UrlEncodeToString(subject.Text,System.Text.Encoding.UTF8);
req+="&&ip="+System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(),System.Text.Encoding.UTF8);
req+="&&date="+System.Web.HttpUtility.UrlEncodeToString(now.ToString(),System.Text.Encoding.UTF8);
req+="&&message="+System.Web.HttpUtility.UrlEncodeToString(message.Text,System.Text.Encoding.UTF8);
//Encode"no"toindicatethatthepostisnotanewpostbutitsareplytoaearliermessage
req+="&&newpost="+System.Web.HttpUtility.UrlEncodeToString("no",System.Text.Encoding.UTF8);
req+="&&previd="+System.Web.HttpUtility.UrlEncodeToString(postid,System.Text.Encoding.UTF8);
//Callthepostmessagepagewithourcustomquery
Page.Navigate("postmessage.aspx?"+req);
}
else
{
errmess.Text="FillinalltheRequiredFields!";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet></head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<%--Includeaheaderfile'header.inc'--%>
<!--#IncludeFile="header.inc"-->
<br>
<divalign=center>
<tableborder=0width=80%cellspacing=2>
<trclass=fohead><thwidth=20%>AuthorName</th>
<thwidth=80%>Message</th></tr>
<%--BelowIamencapsulatingtheemailoftheauthoroverthenameoftheauthor
sothatwhenyouclickontheauthorae-mailgetssenttohim
AlsoIamgetingtheDateTimefromtheDataBaseandDisplayingtheDateandTimeseparately--%>
<trclass=folight><tdrowspan=2align="center"><%="<ahref=mailto:"+dr["email"]+">"+dr["name"]+"</a>"%><br>
<fontsize=1><%=dr["date"].ToString().ToDateTime().ToShortDateString()%><br>
<%=dr["date"].ToString().ToDateTime().ToShortTimeString()%></font>
</td>
<td><b>Subject:</b><%=dr["subject"]%></td></tr>
<trclass=folight>
<td><pre><%=dr["message"]%></pre></td>
</tr>
<%--GetalltherepliestotheOriginalpostandshowthem--%>
<%intno=rs.Tables["reply"].Rows.Count;
if(no>0)
{
for(intj=0;j<no;j++)
{
DataRowrd=rs.Tables["reply"].Rows[j];
%>
<trclass=fodark>
<tdalign="center"><%="<ahref=mailto:"+rd["email"]+">"+rd["name"]+"</a>"%><br>
<fontsize=1><%=rd["date"].ToString().ToDateTime().ToShortDateString()%><br>
<%=rd["date"].ToString().ToDateTime().ToShortTimeString()%></font>
</td>
<td><pre><%=rd["message"]%></pre></td>
</tr>
<%
}
}
%>
</table>
</div>
<h3align="center"class="fodark"><ahref=forum.aspx>ClickHere</a>togotobacktoForum.
<br>ReplytotheAbovePost.</h3>
<br>
<asp:labelid="errmess"text=""style="COLOR:#ff0000"runat="server"/>
<formrunat="server">
<tableborder="0"width="80%"align="center">
<tr>
<tdclass="fohead"colspan=2><b>ReplytothePost</b></td>
</tr>
<trclass="folight">
<td>Name:</td>
<td><asp:textboxtext=""id="name"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:textboxtext=""id="email"runat="server"/><fontcolor=#ff0000>*</font></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:textboxtest=""id="subject"width=200runat="server"/><fontcolor=#ff0000>*</font>
</td></tr>
<trclass="folight">
<td>Message:</td>
<td>
<asp:TextBoxid=messagerunat="server"
Columns="30"Rows="15"TextMode="MultiLine"></asp:TextBox></td>
</tr>
<trclass=folight>
<tdcolspan=2>
<asp:Buttonclass=fodarkid=writeonClick=Submit_Clickrunat="server"Text="Submit"></asp:Button></td></tr>
</table>
</form><br>
<br><!--#IncludeFile="footer.inc"-->
</body></html>
用asp.net写的论坛程序--上贴保存
3)postmessage.aspx:-ThepagewhichsaveddatatotheDatabase
<%@ImportNamespace="System"%>
<%@AssemblyName="System.Data"%>
<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.ADO"%>
<%@PageLanguage="C#"Debug="true"%>
<html>
<head>
<title>ThankYouforPosting!</title>
<scriptlanguage="C#"runat="server">
//executethisscriptwhenthepageloads
voidPage_Load(ObjectSrc,EventArgsE)
{
//ifthepageiscalledfromanotherpage
if(!Page.IsPostBack){
//GetalltheParametersfromtheQuerystring
stringname=Request.Params["name"];
stringemail=Request.Params["email"];
stringsubject=Request.Params["subject"];
stringip=Request.Params["ip"];
stringdate=Request.Params["date"];
stringmessage=Request.Params["message"];
boolnewmess=true;
stringprevid="1";
//CheckifthepostisaNewtopicorareplytoanewtopic
if(Request.Params["newpost"].Equals("no"))
{
//ifitsareplythengetthepostidcalledasprevidhere
newmess=false;
previd=Request.Params["previd"];
}
//Ifthepostisanewtopicthenfollowthebelowroutine
if(newmess)
{
//Thestringforthepathtothedatabase,ifyourdatabaseisinsomeother
directorytheneditthepath
//ofthisvariable
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=
"+Server.MapPath(".\\db\\board.mdb");
//GetaADOConnectiontothedatabase
ADOConnectionmyConn=newADOConnection(strConn);
//TheSQLSelectstatement
stringstrCom="Selectpostidfromnewpost";
//CreateaADOCommandsincewewantaADODataReaderlater
ADOCommandmyCommand=newADOCommand(strCom,myConn);
//Opentheconnection
myConn.Open();
ADODataReaderreader;
//ExecutethecommandandgettheDatainto"reader"
myCommand.Execute(outreader);
inti=1;
//Getthecurrentnumberofrecordspresentinthedatabase.
while(reader.Read())
{
i++;
}
reader.Close();
//buildtheSQLstatementtoinsertintotheDatabase
stringinsertStr="INSERTINTOnewpostVALUES("
+i+",'"
+name+"','"
+email+"','"
+subject+"','"
+ip+"','"
+date+"','"
+message+"',0,0)";
myCommand.CommandText=insertStr;
//SincetheSQLstatementdoesnotreturnanyoutputuse"ExecuteNonQuery()method
myCommand.ExecuteNonQuery();
//Closetheconnection
myConn.Close();
}
else
{
//Iftheposteddataisareplytoatopicthenfollowthebelowprocedure
//stringforthepathtothedatabase,ifyourdatabaseisstoredinsomeotherdirectorythen
//editthepathhere
stringstrConn=@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+
Server.MapPath(".\\db\\board.mdb");
ADOConnectionmyConn=newADOConnection(strConn);
//SQLstatementtoselectthereplyid
stringstrCom="Selectreplyidfromreply";
//createaADOCommand
ADOCommandmyCommand=newADOCommand(strCom,myConn);
//OpentheConnection
myConn.Open();
ADODataReaderreader;
//ExecutethecommandandgettheDatainto"reader"
myCommand.Execute(outreader);
inti=1;
//Getthecurrentnumberofrecordspresentinthedatabase.
while(reader.Read())
{
i++;
}
reader.Close();
//Buildastatementtoinsertthevaluesintothereplytable
stringinsertStr="INSERTINTOreplyVALUES("
+i+",'"
+name+"','"
+email+"','"
+subject+"','"
+ip+"','"
+date+"','"
+message+"',"
+previd+")";
myCommand.CommandText=insertStr;
//ExecuteNonQuery-sincethecommanddoesnotreturnanything
myCommand.ExecuteNonQuery();
//stringtogettherepliescolumnfromthenewposttable
stringreplyno="SELECTrepliesFROMnewpostWHEREpostid="+previd;
myCommand.CommandText=replyno;
//Executecommandandgetthereader
myCommand.Execute(outreader);
//readthefirstrecord(remembertherecanonlybeonerecordinthereadersincepostidisunique)
reader.Read();
//Getthe"Int16"valueofthenumberofrepliesfromtherepliescolumninthenewposttable
intrep=reader.GetInt16(0);
reader.Close();
rep++;
//SQLstatementtoupdatetherepliesfieldinthenewposttable
stringupdtStr="UPDATEnewpostSETreplies="+rep
+"WHERE(postid="+previd+")";
myCommand.CommandText=updtStr;
//ExecuteNonQuerrywhy??IguessUshouldknowbynow!
myCommand.ExecuteNonQuery();
myConn.Close();
}
//getthedifferentParametersfromthequerystringandstoreit
//torespectiveLabels
NameLabel.Text=name;
EmailLabel.Text=email;
SubjectLabel.Text=subject;
MessageLabel.Text=message;
}
else
{
//elsedisplayanerror
errmess.Text="ThisPageCannotbecalleddirectly.IthastobecalledfromtheFormpostingpage.<br>";
}
}
</script>
<LINKhref="mystyle.css"type=text/cssrel=stylesheet>
</head>
<bodytopmargin="0"leftmargin="0"rightmargin="0"marginwidth="0"marginheight="0">
<!--#IncludeFile="header.inc"-->
<center>
<asp:labelid="errmess"text=""style="color:#FF0000"runat="server"/>
<h2class="fodark"><b>ThankYou,forpostingontheMessageBoard.</b></h2>
<tablealign=centerwidth="60%"border="0"cellspacing="2"cellpadding="1">
<trclass="fohead"><tdcolspan="2">TheinformationYouPosted!</td></tr>
<trclass="folight">
<td>Name:</td>
<td><asp:labelid="NameLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>E-Mail:</td>
<td><asp:labelid="EmailLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>Subject:</td>
<td><asp:labelid="SubjectLabel"text=""runat="server"/></td>
</tr>
<trclass="folight">
<td>Message:</td>
<td><asp:labelid="MessageLabel"text=""runat="server"/></td>
</tr>
</table>
<br>
<h4class="fodark"><ahref="forum.aspx">Clickhere</a>togobacktotheForum.<br>
<%--Alittleworktoshowthelinktoreturnbacktothepageif,thepostwasareply--%>
<%if(Request.Params["previd"]!=null)
{%>
<ahref='reply.aspx?postid=<%=Request.Params["previd"]%>'>Clickhere</a>togoback
whereyoucamefrom.
<%}%>
</h4>
</center>
<!--#IncludeFile="footer.inc"-->
</body>
</html>
相关推荐
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 《ASP...
ASP.NET高级程序设计ASP.NET高级程序设计ASP.NET高级程序设计ASPASP.NET高级程序设计ASP.NET高级程序设ASP.NET高级程序设计ASP.NET高级程序设计ASP.NET高级程序设计ASP.NET高级程序设计ASP.NET高级程序设计ASP.NET...
用ASP.NET实现的网页版的幸运转盘抽奖程序,下载完直接可以运行,好用。
本卷从最易于理解和使用的那部分入手,介绍ASP.NET AJAX框架中能够与传统ASP.NET无缝对接的服务器端部分,包括服务器端ASP.NET AJAX Extensions与ASP.NET AJAX Control Toolkit。这部分内容不需要读者有任何的客户端...
asp.net版小程序微信支付接口文件,含web.config里参数配置,另二个ashx接口文件,绝对可用,另小程序和内嵌H5,授权登陆请参考sn.txt文件内容咨询解决!
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 ...
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 ...
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 ...
IIS7.0 ASP.NET 应用程序生命周期ASP.NET 应用程序生命周期ASP.NET 应用程序生命周期
用ASP.Net写一个发送ICQ信息的程序
周峰《ASP.NET 3.5网络程序设计案例集锦》源代码
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 ...
[Apress] ASP.NET 4 高级程序设计 (C# 2010 实现) (英文版) [Apress] Pro ASP.NET 4 in C# 2010 (E-Book) ☆ 图书概要:☆ ASP.NET 4 is the principal standard for creating dynamic web pages on the Windows ...
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax技术制作快速响应的页面,以及如何使用微软的ASP.NET AJAX平台。另外,还专门介绍了ASP.NET 4新增的功能,如MVC和动态数据等。 《ASP...
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax技术制作快速响应的页面,以及如何使用微软的ASP.NET AJAX平台。另外,还专门介绍了ASP.NET 4新增的功能,如MVC和动态数据等。 《ASP...
一个页面登陆的.NET的程序,所用知识点:页面跳转、传值 需要注册后才能登陆
将ASP.NET Core应用程序部署至生产环境中(CentOS7) 将ASP.NET Core应用程序部署至生产环境中(CentOS7) 将ASP.NET Core应用程序部署至生产环境中(CentOS7)
ASP.net程序语法 对ASP.net程序语法有详细的介绍 是邮电大学的知识
此外,《ASP.NET 4高级程序设计(第4版)》专门提供了两章的内容来教你如何用Ajax 技术制作快速响应的页面,以及如何使用微软的ASP.NETAJAX平台。另外,还专门介绍了ASP.NET4 新增的功能,如MVC 和动态数据等。 《ASP...
ASP.NET高级程序设计(第3版)源码 ASP.NET高级程序设计(第3版)源码 ASP.NET高级程序设计(第3版)源码 ASP.NET高级程序设计(第3版)源码 ASP.NET高级程序设计(第3版)源码