ASP.Net MVC Error: must declare a body because it is not marked abstract, extern, or partial

Last Reply 5 days ago By dharmendr

Posted 7 days ago

Error must declare a body because it is not marked abstract, extern, or partial

#region Assembly DataLayerB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// D:\Project\Amlakeabdi\AmlakeAbdi\AmlakeAbdi\Bin\DataLayerB.dll
#endregion
 
using System.Data.SqlClient;
 
namespace DataLayerB
{
    public static class General
    {
        public static object ExecuteScaler(string spName, SqlParameter[] parameters);
        public static T ExecuteScalerB<T>(string spName, SqlParameter[] parameters);
        public static SqlCommand GetCommand(string spName, SqlConnection conn);
        public static SqlConnection GetConnection();
        public static SqlConnection GetConnectionSession();
    }
}

 

   private void BindTransfer1()
   {
       Ddlvagozari.Items.Clear();
       Ddlvagozari.Items.Add(new ListItem("All", ""));
       Ddlvagozari.AppendDataBoundItems = true;
       using (SqlConnection conn = General.GetConnection())
       {
           using (SqlCommand _cmd = General.GetCommand("selecttransfer1", conn))
           {
               _cmd.Parameters.AddWithValue("@Type", Ddltype.SelectedItem.Text);
              
               conn.Open();
               Ddlvagozari.DataSource = _cmd.ExecuteReader();
               Ddlvagozari.DataTextField = "Transfer";
               Ddlvagozari.DataBind();
           }
       }
   }

 

Posted 5 days ago

Hi nedash,

You have to do in this way or you can use the interface concept with the method body and this interface will be inherited by your Business logic class.

As per your code the error explains that you need declare a body i.e. get and set property.

Code

public static class General
{
    public static object ExecuteScaler(string spName, SqlParameter[] parameters)
    {
        return new object { };
    }
    public static SqlCommand GetCommand(string spName, SqlConnection conn)
    {
        SqlCommand cmd = new SqlCommand(spName, conn);
        cmd.CommandType = CommandType.StoredProcedure;
        return cmd;
    }
    public static SqlConnection GetConnection()
    {
        string connection = ConfigurationManager.ConnectionStrings["Sample"].ConnectionString;
        SqlConnection con = new SqlConnection(connection);
        return con;
    }
    public static SqlConnection GetConnectionSession()
    {
        string connection = ConfigurationManager.ConnectionStrings["SampleSession"].ConnectionString;
        SqlConnection con = new SqlConnection();
        return con;
    }
}

Check the below link for more details.

https://www.c-sharpcorner.com/UploadFile/3d39b4/crud-using-the-repository-pattern-in-mvc/