以下是增加帖子的代码:
//增加新主题
public void addNewTopic(object sender, System.EventArgs e)
{
//基于连接的insert
string sql = "insert into T_Topic (fchrTopicID,fchrTopicCaption,fchrTopicDetail,fchrOperatorID,fdtmDate,fbitIsTOP,fbitIsGood,fbitNoUsed,fchrFunctionID)"+
" values(@fchrTopicID,@fchrTopicCaption,@fchrTopicDetail,@fchrOperatorID,@fdtmDate,@fbitIsTOP,@fbitIsGood,@fbitNoUsed,@fchrFunctionID)";
SqlConnection oConn = new SqlConnection(CONNSTRING);
SqlCommand oCommand = new SqlCommand(sql,oConn);
oCommand.Parameters.Add(new SqlParameter("@fchrTopicID",SqlDbType.UniqueIdentifier,16));
oCommand.Parameters.Add(new SqlParameter("@fchrOperatorID",SqlDbType.VarChar,50));
oCommand.Parameters.Add(new SqlParameter("@fchrFunctionID",SqlDbType.VarChar,50));
oCommand.Parameters.Add(new SqlParameter("@fchrTopicCaption",SqlDbType.VarChar,50));
oCommand.Parameters.Add(new SqlParameter("@fchrTopicDetail",SqlDbType.VarChar,1000));
oCommand.Parameters.Add(new SqlParameter("@fdtmDate",SqlDbType.DateTime,8));
oCommand.Parameters.Add(new SqlParameter("@fbitIsTop",SqlDbType.Bit ,1));
oCommand.Parameters.Add(new SqlParameter("@fbitIsGood",SqlDbType.Bit ,1));
oCommand.Parameters.Add(new SqlParameter("@fbitNoUsed",SqlDbType.Bit ,1));
string strUID="";
string strFunctionID="";
strUID = Request.QueryString["UID"];
strFunctionID = Request.QueryString["id"];
InnerFunction oFunction = new BusObjectForum.InnerFunction();
oCommand.Parameters["@fchrTopicID"].Value = oFunction.getNewID();
oCommand.Parameters["@fchrOperatorID"].Value= "{" + strUID + "}";
oCommand.Parameters["@fchrFunctionID"].Value= "{" + strFunctionID + "}";
oCommand.Parameters["@fchrTopicCaption"].Value=txtCaption.Text;
oCommand.Parameters["@fchrTopicDetail"].Value=txtDesc.Text;
oCommand.Parameters["@fdtmDate"].Value=System.DateTime.Now;
oCommand.Parameters["@fbitIsTop"].Value=false;
oCommand.Parameters["@fbitIsGood"].Value=false;
oCommand.Parameters["@fbitNoUsed"].Value=false;
oConn.Open();
try //完成对数据库Insert的操作
{
oCommand.ExecuteNonQuery();
//运行一段客户端代码,用于关闭窗口
String stringBuffer = "<script language=JavaScript> " ;
stringBuffer += "window.close();";
stringBuffer += "</script>";
if(!this.IsClientScriptBlockRegistered("MyScript"))
{
// this.RegisterClientScriptBlock("MyScript", stringBuffer);
Response.Write(stringBuffer);
// sScript
}
}
catch(Exception exp)
{
Response.Write(exp.Message);
}
oConn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtCaption.TextChanged += new System.EventHandler(this.txtCaption_TextChanged);
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void txtCaption_TextChanged(object sender, System.EventArgs e)
{
}
private void btnOK_Click(object sender, System.EventArgs e)
{
String stringBuffer = "<script language=JavaScript> " ;
btnOK.Attributes.Add("OnClick",stringBuffer +="window.close()");
}
}
}