Asp+| program This is my first time to write, and please give us more advice
Only watched a day of csharp on dumb to try, reference the NGWS help document, wrote a message board applet.
This program uses SQL SERVER7, there are only 4 fields in the library:
[Guestbook]
book_id
UserName
Post_time
Content
Because of the CSharp master is not good, write a bit messy, in fact, many places can write a simple point. The output data can be used in different ways, I used the
The server has its own control repeater to output, and can also read data in a getstring way. There are a lot of places worth studying, oh, huh.
In addition to the data check, Microsoft's document said there is a server-side check control, in fact, there are several, very complex, too much e-wen, I still
Look, if you have any experience, you might as well teach me.
By the way, there are a lot of wrong things in the NGWS document, damn it! :(
<%@ 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> Delete message! </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> message success!" </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>
<body>
<title> Message Board </title>
<center>
<table>
<div Id=message runat=server></div>
<p><a href= "guest.aspx" > Refresh </a></p>
<form action=guest.aspx method=post>
<tr><td> Name: </td><td><input type=text name=username size=10></td></tr>
<TR><TD valign=top> message: </td><td><textarea colspan=30 rows=4 name=content></ Textarea></td></tr>
<TR><TD colspan=2><input type=submit value= "Save" ></td></tr>
<input Type=hidden name=action value=save>
</table>
</form>
<table>
<asp:repeater id= "mydatalist" runat= "Server" >
<template name= "ItemTemplate" >
<tr>
<td> Name: </td><td><%# DataBinder.Eval (Container.DataItem, "UserName")%> <a
href= "guest.aspx?action=del&book_id=<%# DataBinder.Eval (Container.DataItem," book_id ")%>" > Delete message
</a></td>
</tr>
<tr>
<td> message time: </td><td><%# DataBinder.Eval (Container.DataItem, "Post_time")%></td>
</tr>
<tr>
<tD> message content: </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><