views:

147

answers:

3

How can i solve "must declare a body because it is not marked abstract, extern, or partial". This problem. Can you show me some advices?

Full Error message is about Save, Update, Delete, Select events...

Full message sample :

GenoTip.DAL._AccessorForSQL.Save(string, System.Collections.Specialized.ListDictionary, System.Data.CommandType)' must declare a body because it is not marked abstract, extern, or partial

This error also return in Update, Delete, Select...

 public abstract class _AccessorForSQL
    {
        public virtual bool Save(string sp, ListDictionary ld, CommandType cmdType);
       public virtual bool Update();
       public virtual bool Delete();
       public virtual DataSet Select();
    }

    class GenAccessor : _AccessorForSQL
    {
        DataSet ds;
        DataTable dt;
        public override bool Save(string sp, ListDictionary ld, CommandType cmdType)
        {
            SqlConnection con = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            try
            {
                con = GetConnection();
                cmd = new SqlCommand(sp, con);
                con.Open();
                cmd.CommandType = cmdType;
                foreach (string ky in ld.Keys)
                {
                    cmd.Parameters.AddWithValue(ky, ld[ky]);
                }
                dr = cmd.ExecuteReader();
                ds = new DataSet();
                dt = new DataTable();
                ds.Tables.Add(dt);
                ds.Load(dr, LoadOption.OverwriteChanges, dt);

            }
            catch (Exception exp)
            {

                HttpContext.Current.Trace.Warn("Error in GetCustomerByID()", exp.Message, exp);
            }
            finally
            {
                if (dr != null) dr.Close();
                if (con != null) con.Close();

            }
            return (ds.Tables[0].Rows.Count > 0) ? true : false;

        }
        public override bool Update()
        {
            return true;
        }
        public override bool Delete()
        {
            return true;
        }
        public override DataSet Select()
        {
            DataSet dst = new DataSet();
            return dst;
        }


        private static SqlConnection GetConnection()
        {
            string connStr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(connStr);
            return conn;
        }
+3  A: 

Either mark them as abstract, or give them an empty body.

Lars Mæhlum
Just to clarify: In the base class that is.
Brian Rasmussen
+1 for ace hair.
runrunraygun
+1  A: 

Your methods Save, Update, Delete and Select don't have bodies. You need to either mark them as abstract or give them bodies (i.e. implement them).

brian
A: 

"virtual" methods can be overridden, but don't need to be. Therefore you need to specify a method body.

If you just want to specify method signatures, declare them as "abstract".

Hans Kesting