Reputation: 2966
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 :
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;
}
Upvotes: 1
Views: 7146
Reputation: 39338
"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".
Upvotes: 0
Reputation: 1080
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).
Upvotes: 1
Reputation: 6102
Either mark them as abstract, or give them an empty body.
Upvotes: 4