我自己正在写一小论坛玩玩,关于发帖有一点小问题? 怕不太好做,没什么思路,CSDN的帖子ID应该不是autonumber形式的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 增加后马上取得最大的ID,并且要求发帖用户是同一个就可以了嘛,这个SQL不难写呀 这样做不太好吧,发完贴子跳到reply.aspx?id=帖子号不行吧 这个是我自己写的论坛的发贴部分,希望对你有帮助using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data.OleDb;namespace 我的主页{ /// <summary> /// BBSReply 的摘要说明。 /// </summary> public class BBSReply : System.Web.UI.Page { protected System.Web.UI.WebControls.Repeater repeat1; protected System.Web.UI.WebControls.TextBox txt1; protected System.Web.UI.WebControls.TextBox txttitle; protected System.Web.UI.WebControls.Label title; protected System.Web.UI.WebControls.LinkButton username; protected System.Web.UI.WebControls.Label content; protected System.Web.UI.WebControls.Label ttime; protected System.Web.UI.WebControls.Label nums; public string theuser; public string thenum1; public string thenum2; //public string content; protected System.Web.UI.WebControls.LinkButton linkdata; protected System.Web.UI.WebControls.Button send; protected System.Web.UI.WebControls.Button clear; public string noteid; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面] if(!Page.IsPostBack) { OleDbConnection cnn; OleDbCommand cmd; OleDbDataReader dr; string strconn; string strsql; theuser=Session["User"].ToString(); noteid=Request["noteid"]; strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb"); strsql="select noteid,username,title,content,ttime,(select count(*) from renotetable where noteid="+System.Convert.ToInt32(noteid)+") from notetable where noteid="+System.Convert.ToInt32(noteid)+""; cnn=new OleDbConnection(strconn); cnn.Open(); cmd=new OleDbCommand(strsql,cnn); dr=cmd.ExecuteReader(); if(dr.Read()) { title.Text=dr.GetString(2).ToString(); username.Text=dr.GetString(1).ToString(); content.Text=dr.GetString(3).ToString(); ttime.Text=dr.GetDateTime(4).ToString(); nums.Text=dr.GetInt32(5).ToString(); txttitle.Text=dr.GetString(2).ToString(); } else { Response.Write("<script language='javascript'>alert('该网面不存在!')</script>"); } dr.Close(); BindGrid(); } } void BindGrid() { OleDbConnection cnn; OleDbDataAdapter dr; DataSet ds=new DataSet(); string strsql; string strconn; strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb"); cnn=new OleDbConnection(strconn); cnn.Open(); strsql="select * from renotetable where noteid="+System.Convert.ToInt32(noteid)+" order by retime desc"; dr=new OleDbDataAdapter(strsql,cnn); dr.Fill(ds,"renotetable"); repeat1.DataSource=ds.Tables["renotetable"].DefaultView; repeat1.DataBind(); cnn.Close(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.username.Click += new System.EventHandler(this.username_Click); this.send.Click += new System.EventHandler(this.send_Click); this.clear.Click += new System.EventHandler(this.clear_Click); this.Load += new System.EventHandler(this.Page_Load); this.linkdata.Click+=new System.EventHandler(this.linkdata_Click); } #endregion private void send_Click(object sender, System.EventArgs e) { OleDbConnection cnn; OleDbCommand cmd; string strconn; string strsql; string sendcontent; sendcontent=txt1.Text.Trim(); noteid=Request["noteid"]; theuser=Session["User"].ToString(); if(theuser.Trim()=="" || theuser.Trim()=="0") { Response.Write("<Script language='javascript'>alert('对不起,您不是本论的会员!')</script>"); } else { if(sendcontent!="") { strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb"); cnn=new OleDbConnection(strconn); cnn.Open(); strsql="insert into renotetable(reusername,noteid,content,retime)values('"+theuser+"','"+System.Convert.ToInt32(noteid)+"','"+sendcontent+"','"+System.DateTime.Now+"')"; cmd=new OleDbCommand(strsql,cnn); cmd.ExecuteNonQuery(); txt1.Text=""; cnn.Close(); BindGrid(); } else { Response.Write("<script language='javascript'>alert('回复内容不能为空!')</script>"); } } } private void clear_Click(object sender, System.EventArgs e) { txt1.Text=""; } private void linkdata_Click(object sender, System.EventArgs e) { theuser=Session["User"].ToString(); if(theuser.Trim()=="" || theuser.Trim()=="0") { Response.Write("<Script language='javascript'>alert('对不起,您不是本论的会员!')</script>"); } else { Response.Redirect("BBSUpdata.aspx?username="+theuser+""); } } private void username_Click(object sender, System.EventArgs e) { Response.Redirect("BBSUser.aspx?user="+username.Text+""); } }} <%@ Page language="c#" Codebehind="BBSReply.aspx.cs" AutoEventWireup="false" Inherits="我的主页.BBSReply" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>回复贴子</title> <META http-equiv="Content-Type" content="text/html; charset=gb2312"> <meta content="Microsoft Visual Studio 7.0" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <style type="text/css">.inputnormal { BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; BORDER-LEFT: #c0c0c0 1px solid; BORDER-BOTTOM: #c0c0c0 1px solid; BACKGROUND-COLOR: #f1f1f1}.inputedit { BORDER-RIGHT: #6699cc 1px solid; BORDER-TOP: #6699cc 1px solid; BORDER-LEFT: #6699cc 1px solid; BORDER-BOTTOM: #6699cc 1px solid; BACKGROUND-COLOR: #cddeed} </style> <LINK href="BBSMain.css" type="text/css" rel="stylesheet"> </HEAD> <body bgColor="#e6eef7" MS_POSITIONING="GridLayout"> <form id="BBSReply" method="post" runat="server"> <center> <table cellSpacing="0" cellPadding="1" width="90%" align="center" border="0"> <tr bgColor="#225bb3"> <td width="10%"><FONT face="宋体"></FONT></td> <td width="25%"><FONT face="宋体"></FONT></td> <td align="right" width="65%"><font color="#ffffff">|</font><font color="#ffffff"><asp:linkbutton id="linkdata" Runat="server">修改资料</asp:linkbutton></font><font color="#ffffff">|</font><font color="#ffffff"><A href="BBSmain.aspx">发表新贴子</A></font><font color="#ffffff">|</font><font color="#ffffff"><A href="BBSmain.aspx?thetype=1"> 我的贴子</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSmain.aspx?thetype=2"> 我参加的贴子</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSAdmin.aspx"> 管理</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSIndex.aspx"> 登录</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSLogin.aspx"> 注册</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="javascript:location.reload()"> 刷新</A></font> <font color="#ffffff">|</font> </td> </tr> </table> <br> <br> <table borderColor="#cccccc" cellSpacing="0" cellPadding="0" width="90%" align="center" border="1"> <tr bgColor="#225bb3"> <td colSpan="2" height="20"><FONT color="#ffffff" size="2"> 贴子主题:</FONT> <asp:label id="title" Runat="server" ForeColor="#ffffff"></asp:label></td> </tr> <tr bgColor="#f6f6f6"> <td align="middle" width="15%" height="100"><font color="#666666" size="2">发 贴 人</font><br> <asp:linkbutton id="username" Runat="server" CssClass="gr2"></asp:linkbutton><br> <font color="#666666" size="2">回复次数:</font><br> <asp:label id="nums" Runat="server" ForeColor="red"></asp:label><br> <asp:label id="ttime" Runat="server" ForeColor="#666666"></asp:label></td> <td vAlign="top" align="left" width="80%"> <asp:Label ID=content Runat=server></asp:Label> </td> </tr> </table> </center> <center><asp:repeater id="repeat1" Runat="server"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <center> <table cellSpacing="0" cellPadding="0" width="90%" align="center" border="1" bordercolor="#cccccc"> <tr bgColor="#225bb3"> <td width="95%" height="20" colspan="2"> <font size="2" color="#ffffff"> 回复主题: <%=title.Text%> </font> </td> </tr> <tr bgcolor="#f6f6f6"> <td width="15%" height="100" align="center"> <font size="2" color="#666666">回复人</font><br> <font size="2" color="#3366cc"> <a href="BBSUser.aspx?user=<%# DataBinder.Eval(Container.DataItem,"ReUsername")%>" title="查看用户资料" class=gr2><%# DataBinder.Eval(Container.DataItem,"ReUsername")%></a> </font> <br> <font size="2" color="#666666"> <%# DataBinder.Eval(Container.DataItem,"ReTime")%> </font> </td> <td width="80%" height="100" valign="top"> <font size="2"> <%# DataBinder.Eval(Container.DataItem,"content")%></font> </td> </tr> </table> </center> </ItemTemplate> <SeparatorTemplate> </SeparatorTemplate> <FooterTemplate> </FooterTemplate> </asp:repeater> <table borderColor="#cccccc" cellPadding="2" width="90%" bgColor="#f6f6f6" border="1"> <tr> <td width="10%"><font color="red">注 意:</font></td> <td align="left" width="90%"><font color="#666666" size="2">请对你的言行负责,遵守国家有关法律、法规、尊重网上道德、文明上网 </font> </td> </tr> <tr> <td width="10%">回复标题:</td> <td align="left" width="90%"><asp:textbox id="txttitle" Runat="server" ReadOnly="True" Columns="70" CssClass="inputnormal"></asp:textbox></td> </tr> <tr> <td vAlign="top" width="10%">回复内容:</td> <td width="90%"><asp:textbox id="txt1" Runat="server" Rows="10" Columns="70" MaxLength=255 TextMode="MultiLine" CssClass="inputnormal" AutoPostBack="False"></asp:textbox></td> </tr> </table> <br> <asp:button id="send" Runat="server" CssClass="inputedit" Text="提交回复"></asp:button> <asp:button id="clear" Runat="server" CssClass="inputedit" Text="重写"></asp:button><br> <br> <hr> 版权所有:<font color="blue">哭过的天空</font></center> </form> </body></HTML> 同意 cnlamar(无中生有) 简单的问题,用的了那么多代码! insert into Table (AA, BB) VALUES (@AA, @BB) SELECT @@IDENTITY AS 'Id' .... int nReturnValue = (int)_comm.ExecuteScalar(); .... Server.Transfer("CC.aspx?Id="+ nReturnValue); http://expert.csdn.net/Expert/topic/2503/2503219.xml?temp=.6832544要不要参考一下? 找不到对象名 Excel导出时,保存窗口一闪而过 想csdn这样的 右下角的消息提示怎么处理的的 或者在页面缩小到那个框变蓝 如何在一个类中调用另一个类中的方法? 菜鸟求助(IE滚动条的设置) asp.net的三层架构 请各位大侠出手帮忙!!奇怪的问题,着急着呢!!! 网站游览问题 SQL语句问题!请高手帮着看看!顶着有分,在线等! C#中有变长数组吗?? 多个数据库服务器数据同步的问题 各位有没有遇到过 在98下的Cookies问题
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;namespace 我的主页
{
/// <summary>
/// BBSReply 的摘要说明。
/// </summary>
public class BBSReply : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Repeater repeat1;
protected System.Web.UI.WebControls.TextBox txt1;
protected System.Web.UI.WebControls.TextBox txttitle;
protected System.Web.UI.WebControls.Label title;
protected System.Web.UI.WebControls.LinkButton username;
protected System.Web.UI.WebControls.Label content;
protected System.Web.UI.WebControls.Label ttime;
protected System.Web.UI.WebControls.Label nums;
public string theuser;
public string thenum1;
public string thenum2;
//public string content;
protected System.Web.UI.WebControls.LinkButton linkdata;
protected System.Web.UI.WebControls.Button send;
protected System.Web.UI.WebControls.Button clear;
public string noteid;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面]
if(!Page.IsPostBack)
{
OleDbConnection cnn;
OleDbCommand cmd;
OleDbDataReader dr;
string strconn;
string strsql;
theuser=Session["User"].ToString();
noteid=Request["noteid"];
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb");
strsql="select noteid,username,title,content,ttime,(select count(*) from renotetable where noteid="+System.Convert.ToInt32(noteid)+") from notetable where noteid="+System.Convert.ToInt32(noteid)+"";
cnn=new OleDbConnection(strconn);
cnn.Open();
cmd=new OleDbCommand(strsql,cnn);
dr=cmd.ExecuteReader();
if(dr.Read())
{
title.Text=dr.GetString(2).ToString();
username.Text=dr.GetString(1).ToString();
content.Text=dr.GetString(3).ToString();
ttime.Text=dr.GetDateTime(4).ToString();
nums.Text=dr.GetInt32(5).ToString();
txttitle.Text=dr.GetString(2).ToString();
}
else
{
Response.Write("<script language='javascript'>alert('该网面不存在!')</script>");
}
dr.Close();
BindGrid();
}
}
void BindGrid()
{
OleDbConnection cnn;
OleDbDataAdapter dr;
DataSet ds=new DataSet();
string strsql;
string strconn;
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb");
cnn=new OleDbConnection(strconn);
cnn.Open();
strsql="select * from renotetable where noteid="+System.Convert.ToInt32(noteid)+" order by retime desc";
dr=new OleDbDataAdapter(strsql,cnn);
dr.Fill(ds,"renotetable");
repeat1.DataSource=ds.Tables["renotetable"].DefaultView;
repeat1.DataBind();
cnn.Close();
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.username.Click += new System.EventHandler(this.username_Click);
this.send.Click += new System.EventHandler(this.send_Click);
this.clear.Click += new System.EventHandler(this.clear_Click);
this.Load += new System.EventHandler(this.Page_Load);
this.linkdata.Click+=new System.EventHandler(this.linkdata_Click); }
#endregion private void send_Click(object sender, System.EventArgs e)
{
OleDbConnection cnn;
OleDbCommand cmd;
string strconn;
string strsql;
string sendcontent;
sendcontent=txt1.Text.Trim();
noteid=Request["noteid"];
theuser=Session["User"].ToString();
if(theuser.Trim()=="" || theuser.Trim()=="0")
{
Response.Write("<Script language='javascript'>alert('对不起,您不是本论的会员!')</script>"); }
else
{
if(sendcontent!="")
{
strconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("data/BBS.mdb");
cnn=new OleDbConnection(strconn);
cnn.Open();
strsql="insert into renotetable(reusername,noteid,content,retime)values('"+theuser+"','"+System.Convert.ToInt32(noteid)+"','"+sendcontent+"','"+System.DateTime.Now+"')";
cmd=new OleDbCommand(strsql,cnn);
cmd.ExecuteNonQuery();
txt1.Text="";
cnn.Close();
BindGrid();
}
else
{
Response.Write("<script language='javascript'>alert('回复内容不能为空!')</script>");
}
}
} private void clear_Click(object sender, System.EventArgs e)
{
txt1.Text="";
} private void linkdata_Click(object sender, System.EventArgs e)
{
theuser=Session["User"].ToString();
if(theuser.Trim()=="" || theuser.Trim()=="0")
{
Response.Write("<Script language='javascript'>alert('对不起,您不是本论的会员!')</script>"); }
else
{
Response.Redirect("BBSUpdata.aspx?username="+theuser+"");
}
} private void username_Click(object sender, System.EventArgs e)
{
Response.Redirect("BBSUser.aspx?user="+username.Text+"");
}
}
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>回复贴子</title>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<style type="text/css">.inputnormal {
BORDER-RIGHT: #c0c0c0 1px solid; BORDER-TOP: #c0c0c0 1px solid; BORDER-LEFT: #c0c0c0 1px solid; BORDER-BOTTOM: #c0c0c0 1px solid; BACKGROUND-COLOR: #f1f1f1
}
.inputedit {
BORDER-RIGHT: #6699cc 1px solid; BORDER-TOP: #6699cc 1px solid; BORDER-LEFT: #6699cc 1px solid; BORDER-BOTTOM: #6699cc 1px solid; BACKGROUND-COLOR: #cddeed
}
</style>
<LINK href="BBSMain.css" type="text/css" rel="stylesheet">
</HEAD>
<body bgColor="#e6eef7" MS_POSITIONING="GridLayout">
<form id="BBSReply" method="post" runat="server">
<center>
<table cellSpacing="0" cellPadding="1" width="90%" align="center" border="0">
<tr bgColor="#225bb3">
<td width="10%"><FONT face="宋体"></FONT></td>
<td width="25%"><FONT face="宋体"></FONT></td>
<td align="right" width="65%"><font color="#ffffff">|</font><font color="#ffffff"><asp:linkbutton id="linkdata" Runat="server">修改资料</asp:linkbutton></font><font color="#ffffff">|</font><font color="#ffffff"><A href="BBSmain.aspx">发表新贴子</A></font><font color="#ffffff">|</font><font color="#ffffff"><A href="BBSmain.aspx?thetype=1">
我的贴子</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSmain.aspx?thetype=2">
我参加的贴子</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSAdmin.aspx">
管理</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSIndex.aspx">
登录</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="BBSLogin.aspx">
注册</A></font> <font color="#ffffff">|</font> <font color="#ffffff"><A href="javascript:location.reload()">
刷新</A></font> <font color="#ffffff">|</font>
</td>
</tr>
</table>
<br>
<br>
<table borderColor="#cccccc" cellSpacing="0" cellPadding="0" width="90%" align="center" border="1">
<tr bgColor="#225bb3">
<td colSpan="2" height="20"><FONT color="#ffffff" size="2">
贴子主题:</FONT>
<asp:label id="title" Runat="server" ForeColor="#ffffff"></asp:label></td>
</tr>
<tr bgColor="#f6f6f6">
<td align="middle" width="15%" height="100"><font color="#666666" size="2">发 贴 人</font><br>
<asp:linkbutton id="username" Runat="server" CssClass="gr2"></asp:linkbutton><br>
<font color="#666666" size="2">回复次数:</font><br>
<asp:label id="nums" Runat="server" ForeColor="red"></asp:label><br>
<asp:label id="ttime" Runat="server" ForeColor="#666666"></asp:label></td>
<td vAlign="top" align="left" width="80%"> <asp:Label ID=content Runat=server></asp:Label>
</td>
</tr>
</table>
</center>
<center><asp:repeater id="repeat1" Runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<center>
<table cellSpacing="0" cellPadding="0" width="90%" align="center" border="1" bordercolor="#cccccc">
<tr bgColor="#225bb3">
<td width="95%" height="20" colspan="2">
<font size="2" color="#ffffff"> 回复主题: <%=title.Text%>
</font>
</td>
</tr>
<tr bgcolor="#f6f6f6">
<td width="15%" height="100" align="center">
<font size="2" color="#666666">回复人</font><br>
<font size="2" color="#3366cc">
<a href="BBSUser.aspx?user=<%# DataBinder.Eval(Container.DataItem,"ReUsername")%>" title="查看用户资料" class=gr2><%# DataBinder.Eval(Container.DataItem,"ReUsername")%></a>
</font>
<br>
<font size="2" color="#666666">
<%# DataBinder.Eval(Container.DataItem,"ReTime")%>
</font>
</td>
<td width="80%" height="100" valign="top">
<font size="2"> <%# DataBinder.Eval(Container.DataItem,"content")%></font>
</td>
</tr>
</table>
</center>
</ItemTemplate>
<SeparatorTemplate>
</SeparatorTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
<table borderColor="#cccccc" cellPadding="2" width="90%" bgColor="#f6f6f6" border="1">
<tr>
<td width="10%"><font color="red">注 意:</font></td>
<td align="left" width="90%"><font color="#666666" size="2">请对你的言行负责,遵守国家有关法律、法规、尊重网上道德、文明上网
</font>
</td>
</tr>
<tr>
<td width="10%">回复标题:</td>
<td align="left" width="90%"><asp:textbox id="txttitle" Runat="server" ReadOnly="True" Columns="70" CssClass="inputnormal"></asp:textbox></td>
</tr>
<tr>
<td vAlign="top" width="10%">回复内容:</td>
<td width="90%"><asp:textbox id="txt1" Runat="server" Rows="10" Columns="70" MaxLength=255 TextMode="MultiLine" CssClass="inputnormal" AutoPostBack="False"></asp:textbox></td>
</tr>
</table>
<br>
<asp:button id="send" Runat="server" CssClass="inputedit" Text="提交回复"></asp:button>
<asp:button id="clear" Runat="server" CssClass="inputedit" Text="重写"></asp:button><br>
<br>
<hr>
版权所有:<font color="blue">哭过的天空</font></center>
</form>
</body>
</HTML>
....
int nReturnValue = (int)_comm.ExecuteScalar();
....
Server.Transfer("CC.aspx?Id="+ nReturnValue);