3) Postmessage.aspx:-the page which saved data to the Database
<%@ Import namespace= "System"%>
<%@ Assembly name= "System.Data"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.ADO"%>
<%@ Page language= "C #" debug= "true"%>
<title>thank for Posting!</title>
<script language= "C #" runat= "Server" >
Execute this script when the page loads
void Page_Load (Object Src, EventArgs E)
{
If the page is called from another page
if (! Page.IsPostBack) {
Get all the Parameters from the Query string
String name = request.params["Name"];
string email = request.params["email"];
String subject = request.params["Subject"];
string IP = request.params["IP"];
String date = request.params["Date"];
String message = request.params[' message '];
BOOL Newmess =true;
String previd = "1";
Check If the post is a new topic or a reply to a new topic
if (request.params["Newpost"]. Equals ("no"))
{
If it a reply then get the PostID called as Previd here
Newmess =false;
Previd = request.params["Previd"];
}
If The post is a new topic then follow the below routine
if (newmess)
{
The string for the ' path to the ' database, if your database is in some
Directory then edit the path
of this variable
String strconn=@ "Provider=Microsoft.Jet.OLEDB.4.0;D ata source=
"+server.mappath (". \\db\\board.mdb ");
Get a adoconnection to the database
ADOConnection myconn = new ADOConnection (strconn);
The SQL Select statement
String strcom = "Select PostID from Newpost";
Create a Adocommand since we want a adodatareader later
Adocommand mycommand =new Adocommand (strcom,myconn);
Open the connection
MyConn.Open ();
Adodatareader reader;
Execute the command and get the Data into "reader"
Mycommand.execute (out reader);
int i=1;
Get the current number of records present in the database.
while (reader. Read ())
{
i++;
}
Reader. Close ();
Build the SQL statement to insert into the Database
String insertstr = "INSERT into Newpost VALUES ("
+i + ", '"
+name+ "', '"
+email+ "', '"
+subject+ "', '"
+ip+ "', '"
+date+ "', '"
+message+ "', 0, 0";
myCommand.CommandText =insertstr;
Since The SQL statement does not return any output with "ExecuteNonQuery" () method
Mycommand.executenonquery ();
Close the connection
Myconn.close ();
}
Else
{
If The posted data is a reply to a topic then follow the below procedure
String for the ' path to the ' database, if your database is stored into some other directory then
Edit the path here
String strconn=@ "provider=microsoft.jet.oledb.4.0;D ata source=" +
Server.MapPath (". \\db\\board.mdb");
ADOConnection myconn = new ADOConnection (strconn);
SQL statement to select the Replyid
String strcom = "Select Replyid from reply";
Create a Adocommand
Adocommand mycommand =new Adocommand (strcom,myconn);
Open the Connection
MyConn.Open ();
Adodatareader reader;
Execute the command and get the Data into "reader"
Mycommand.execute (out reader);
int i=1;
Get the current number of records present in the database.
while (reader. Read ())
{
i++;
}
Reader. Close ();
Build a statement to inserts the values into the reply table
String insertstr = "INSERT into reply VALUES ("
+i + ", '"
+name+ "', '"
+email+ "', '"
+subject+ "', '"
+ip+ "', '"
+date+ "', '"
+message+ "',"
+previd+ ")";
myCommand.CommandText =insertstr;
Executenonquery-since the command does not return anything
Mycommand.executenonquery ();
String to get the replies column from the Newpost table
String Replyno = "Select replies from Newpost WHERE PostID =" +previd;
myCommand.CommandText =replyno;
Execute command and get the reader
Mycommand.execute (out reader);
Read the "Remember there can only one" in "reader since PostID is unique"
Reader. Read ();
Get the "Int16" value of the number of replies from the replies column in the Newpost table
Int rep =reader. GetInt16 (0);
Reader. Close ();
rep++;
SQL statement to update the replies field in the Newpost table
String updtstr = "UPDATE newpost SET replies =" +rep
+ "WHERE (PostID =" +previd+ ")";
myCommand.CommandText = Updtstr;
Executenonquerry why?? I guess U should know by now!
Mycommand.executenonquery ();
Myconn.close ();
}
Get the different Parameters from the query string and store it
to respective Labels
Namelabel.text = name;
emaillabel.text= email;
Subjectlabel.text=subject;
Messagelabel.text=message;
}
Else
{
else display an error
Errmess. Text= "This Page cannot is called directly. It has to is called from the Form posting Page.<br> ";
}
}
</script>
<link href= "Mystyle.css" Type=text/css rel=stylesheet>
<body topmargin= "0" leftmargin= "0" rightmargin= "0" marginwidth= "0" marginheight= "0" >
<!--#Include file= "Header.inc"-->
<center>
<asp:label id= "errmess" text= "style=" color: #FF0000 "runat=" Server "/>
<H2 class= "Fodark" ><b>thank you, for posting on the message board.</b><table align=center width= "60%" border= "0" cellspacing= "2" cellpadding= "1" >
<tr class= "Fohead" ><td colspan= "2" >the information you posted!</td></tr>
<tr class= "Folight" >
<td>name:</td>
<td><asp:label id= "Namelabel" text= "" runat= "Server"/></td>
</tr>
<tr class= "Folight" >
<td>e-mail:</td>
<td><asp:label id= "Emaillabel" text= "" runat= "Server"/></td>
</tr>
<tr class= "Folight" >
<td>subject:</td>
<td><asp:label id= "Subjectlabel" text= "" runat= "Server"/></td>
</tr>
<tr class= "Folight" >
<td>message:</td>
<td><asp:label id= "Messagelabel" text= "" runat= "Server"/></td>
</tr>
</table>
<br>
<%--a little work to show the "link to" the page if, the post was a reply--%>
<% if (request.params["Previd"]!=null)
{%>
<a href= ' reply.aspx?postid=<%=request.params["Previd"]%> ' > Click here </a>to go back
where you came from.
<%}%>
</center>
<!--#Include file= "Footer.inc"-->
</body>