日期:2013-10-03  浏览次数:20613 次

首先,我们要来定义一个数据库表,以保存舆论调查的想关数据,看下面这个表:
/*新闻调查表*/
if exists(select * from sysobjects where id = object_id('Survey'))
   drop table Survey
go

create table Survey
(
  ID        int         identity Primary key    not null ,
  SurveyID    varchar(20)    default ""         not null ,
  Kind        tinyint        default 0        not null ,
  Title        nvarchar(100)    default ""        not null ,
  Description    nvarchar(255)    default ""        not null ,
  Amount    int        default 0         not null ,
  BeginTime    datetime    default getdate()    not null ,
  EndTime    datetime    default getdate()    not null ,
  Active    bit        default 0        not null
)        
go

好了,数据库建好了,我可以从上面的survey基类中继承出具体的子类,比如说我现在要做一个同足球相

关的调查,那就做这么一个类:

namespace Football
{
    using System;
    using MyClass.Util ;
    using System.Data.SQL ;
    using System.Collections ;
    /// <summary>
    ///    足球舆论调查
    /// </summary>
    /// <remarks>
    /// 从MyClass.Util.Survey类继承而来
    /// </remarks>
    public class FootballSurvey : MyClass.Util.Survey
    {


        public FootballSurvey()
        {
        }


        /// <summary>
        /// 重载父类虚函数
        /// </summary>
        /// <param name="a_intID">该调查的数据库id </param>
        public override void LoadFromDatabase(string a_strID)
        {
            MyClass.Util.MyConnection myConn = new MyConnection() ;
            SQLCommand myCommand = new SQLCommand() ;
            myCommand.CommandText = "up_GetSurvey" ;
            myCommand.CommandType = System.Data.CommandType.StoredProcedure ;

            try
            {
                myConn.Open() ;