0

I want to access the internal method how to access pleas help Business layer class

internal DataTable SaveCustomerDetail() {
    SqlParameter[] parameters = new SqlParameter[7];
    parameters[0] = DataAccesLayer.Addparameters("@CustomerName", CustomerName, SqlDbType.VarChar, 100);
    parameters[1] = DataAccesLayer.Addparameters("@CustomerEmailID", CustomerEmailIDl, SqlDbType.VarChar, 100);
    parameters[2] = DataAccesLayer.Addparameters("@CustomerPhoneNumber",CustomerPhoneNumber, SqlDbType.VarChar, 100);
    parameters[3] = DataAccesLayer.Addparameters("@CustomerAddress", CustomerAddress, SqlDbType.VarChar, 100);
    parameters[4] = DataAccesLayer.Addparameters("@TotalProducts", totalproducats, SqlDbType.Int, 100);
    parameters[5] = DataAccesLayer.Addparameters("@TotalPrice", totalprice, SqlDbType.Int, 100);
    parameters[6] = DataAccesLayer.Addparameters("@PaymentMethod", PaymentMethod, SqlDbType.VarChar, 100);
    DataTable dt = DataAccesLayer.ExecuteDTBbyprocedure("SP_SAVECUSTOMERDETAIL",parameters);
    return dt;
}

This .cs where i want to acces the internal Method method:

protected void btnplaceorder_Click(object sender, EventArgs e)
{
    string productsid = string.Empty;
    DataTable dt;
    if (Session["Mycart"] != null) {
        dt = (DataTable)Session["Mycart"];
        BussinessLayer B = new BussinessLayer()
        {
            CustomerName = txtcustomername.Text,
            CustomerEmailIDl = txtcustomeremailid.Text,
            CustomerAddress = txtcustomeraddress.Text,
            CustomerPhoneNumber = txtphoneno.Text,
            totalproducats = Convert.ToInt32(txttotalproducts.Text),
            totalprice = Convert.ToInt32(txttotalprice.Text),
            PaymentMethod = rblpaymentmode.SelectedItem.Text
        };
        DataTable dtResult = B.SaveCustomerDetail();
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
RATHORE
  • 41
  • 6
  • So what's the problem? – Izzy Apr 30 '15 at 08:04
  • Error 1 'BussinessLayer' does not contain a definition for 'SaveCustomerDetail' and no extension method 'SaveCustomerDetail' accepting a first argument of type 'BussinessLayer' could be found (are you missing a using directive or an assembly reference?) its showing above error – RATHORE Apr 30 '15 at 08:05
  • Are they in the same `namespace`? – Izzy Apr 30 '15 at 08:24
  • yes they are in same namespace – RATHORE Apr 30 '15 at 08:45

1 Answers1

0

Make the method public, like public DataTable SaveCustomerDetail, this is the simplest way.

If your application is designed on a View - ViewModel - Model pattern, as it seems, the business layer you are trying to access is located in a different assembly than your presentation layer. This means they are located in different dll's (projects).

So what you are trying to do is to access the internal DataTable SaveCustomerDetail from another dll, which is not ok. You can only access a public method from another dll.

You can think of it this way: your event btnplaceorder_Click is part of a control in a presentation layer, while your internal method DataTable SaveCustomerDetail is part of the business layer. btnplaceorder_Clickjust does not know that there is a method called DataTable SaveCustomerDetail in your code, because you made it internal. So to make it visible to everyone who wants to call it, no matter where in your code, just make it public.

You can read more on differences between internal - protected - public here: internal vs public in c#.

And maybe it will help you to know about the View Model design pattern: https://stackoverflow.com/search?q=view+model+pattern.

Community
  • 1
  • 1
marcus
  • 333
  • 6
  • 14
  • http://stackoverflow.com/questions/29972094/how-to-access-internal-method this is further explatnation – RATHORE May 01 '15 at 12:50