帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
利用c#制作简单的留言板(1)
作者:天啦 发布时间:2005-03-12 来源:Chinaasp论坛
首先要感谢bigeagle的帮助,这个也是参考她的bbs做成的
留言板分三个模块:列出留言列表、显示详细内容、发表留言
notepage.cs
namespace notpage
{
using System;
using System.Data.SQL ;
using System.Data ;
using System.Collections ;
</P><P>
////////////////////////////////////////////////////////////////////
//
// Class Name : 留言板
//
// Description: 构造一个留言板对象
//
// date: 2000/06/06
//
// 作者: 天啦
/// ////////////////////////////////////////////////////////////////</P><P>
/// <summary>
/// Summary description for notepage.
/// </summary>


public class notepage
{
//私有变量

private int n_intID ; //ID编号
private string n_strTitle ; //主题
private string n_strAuthor ; //留言人
private string n_strContent ; //留言内容
private DateTime n_dateTime ; //留言时间</P><P>
//属性
</P><P> public int ID
{
get
{
return n_intID ;
}
set
{
n_intID = value;
}
}</P><P> public string Title
{
get
{
return n_strTitle ;
}
set
{
n_strTitle = value;
}
}</P><P> public string Author
{
get
{
return n_strAuthor ;
}
set
{
n_strAuthor = value ;
}
}
public string Content
{
get
{
return n_strContent ;
}
set
{
n_strContent = value ;
}
}
public DateTime adddate
{

get
{
return n_dateTime;
}
set
{
n_dateTime = value;
}
}
//构造函数
public notepage()
{
//
// TODO: Add Constructor Logic here
//
this.n_intID = 0 ;
this.n_strTitle = "" ;
this.n_strAuthor = "" ;
this.n_strContent = "" ;
this.n_dateTime = System.DateTime.Now;

}</P><P> /// <summary>
///
/// 取得留言的内容
///
/// </summary>
/// <param name="a_intID"> </param>
public notepage GetTopic(int a_intID)
{
//
// TODO: Add Constructor Logic here
//
</P><P>
//读取数据库
myconn myConn = new myconn();

SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicInfo" ; //调用存储过程
myCommand.CommandType = CommandType.StoredProcedure ;
myCommand.Parameters.Add(new SQLParameter("@a_intTopicID" , SQLDataType.Int)) ;
myCommand.Parameters["@a_intTopicID"].Value = a_intID ;</P><P> notepage objNp = new notepage();
try
{

myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;
if (myReader.Read())
{
objNp.ID = (int)myReader["ID"] ;
objNp.Title = (string)myReader["Title"] ;
objNp.Author = (string)myReader["Author"] ;
objNp.Content = (string)myReader["Content"];
objNp.adddate = (DateTime)myReader["adddate"];
}
</P><P>
//清场
myReader.Close();
myConn.Close() ;</P><P> }
catch(Exception e)
{
throw(new Exception("取贴子失败:" + e.ToString())) ;
}
return objNp;

}</P><P> /// <summary>
///
/// 目的:将留言的内容入库
///
/// 利用构造函数来传递信息
///
/// </summary>
/// <param name="n_Topic"> </param>
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Add Constructor Logic here
//

//读取数据库
myconn myConn = new myconn();

SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_addTopic" ; //调用存储过程
myCommand.CommandType = CommandType.StoredProcedure ;
myCommand.Parameters.Add(new SQLParameter("@a_strTitle" , SQLDataType.VarChar,100)) ;
myCommand.Parameters["@a_strTitle"].Value = n_Topic.Title ;</P><P> myCommand.Parameters.Add(new SQLParameter("@a_strAuthor" , SQLDataType.VarChar,50)) ;
myCommand.Parameters["@a_strAuthor"].Value = n_Topic.Author ;</P><P> myCommand.Parameters.Add(new SQLParameter("@a_strContent" , SQLDataType.VarChar,2000)) ;
myCommand.Parameters["@a_strContent"].Value = n_Topic.Content ;</P><P> try
{

myConn.Open() ;
myCommand.ExecuteNonQuery() ;

//清场

myConn.Close() ;</P><P> }
catch(Exception e)
{
throw(new Exception("取贴子失败:" + e.ToString())) ;
}
return true;

</P><P> }</P><P>
/// <summary>
/// 取的贴子列表
/// </summary>
/// <remarks>
/// 返回一个Topic数组
/// </remarks>
public ArrayList GetTopicList()
{
//定义一个forum数组做为返回值
ArrayList arrForumList =new ArrayList() ;</P><P> //从数据库中读取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicList" ; //调用存储过程
myCommand.CommandType = CommandType.StoredProcedure ;</P><P> try
{
myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;</P><P> for (int i = 0 ; myReader.Read() ; i++)
{
notepage objItem = new notepage() ;
objItem.ID = myReader["ID"].ToString().ToInt32() ;
objItem.Title = myReader["Title"].ToString() ;
objItem.Author = myReader["Author"].ToString() ;
objItem.adddate = myReader["adddate"].ToString().ToDateTime();
objItem.Content = myReader["Content"].ToString();

arrForumList.Add(objItem) ;
}</P><P>
//清场
myReader.Close();
myConn.Close() ;</P><P> }
catch(SQLException e)
{
throw(new Exception("数据库出错:" + e.ToString())) ;
//return null ;
}</P><P> return arrForumList ;
}

}
}


  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·利用ASP在线维护数据库  (2005-03-12)
 ·在ASP中利用Oracle Object for O  (2005-03-12)
 ·利用ASP远程注册DLL的方法  (2005-03-12)
 ·利用ASP远程注册DLL的方法  (2005-03-12)
 ·利用索引服务(Indexing Service)  (2005-03-12)
 ·利用ASP改进文档上载控件  (2005-03-12)
 ·利用ASP存取各种常用类型数据库(  (2005-03-12)
 ·利用ASP存取各种常用类型数据库(  (2005-03-12)
 ·利用ASP存取各种常用类型数据库(  (2005-03-12)
 ·利用ASP存取各种常用类型数据库(  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统