7

I would like to populate my text boxes with values based on the selection from my drop down list.

DAL:

public static string GetTicket(collection b)
{
    try
    {

        string returnValue = string.Empty;
        DB = Connect();
        DBCommand = connection.Procedure("getTicket");
        DB.AddInParameter(DBCommand, "@SupportRef", DbType.String, b.SupportRef1);

        var myReader = DBCommand.ExecuteReader();
        while (myReader.Read())
        {
            returnValue = myReader.GetString(0);
        }

        return returnValue;
    }

    catch (Exception ex)
    {
        throw ex;
    }

BLL:

   public string returnTicket(collection b)
   {
       try
       {
           string ticket = DAL.data.GetTicket(b);
           return ticket;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }

PL:

protected void ddl_Customers_SelectedIndexChanged(object sender, EventArgs e)
{
    string selectedValue = ddl_Customers.SelectedValue.ToString();

    //populate the text boxes
    txtSupportRef.Text = bobj.returnTicket(selectedValue);
}

My Stored Procedure has got a variable called SupportRef which needs a value before it can return results.

I get the following errors:

The best overloaded method match for 'BLL.business.returnTicket(DAL.collection)' 
has some invalid arguments

AND

Argument 1: cannot convert from 'string' to 'DAL.collection'
PriceCheaperton
  • 5,071
  • 17
  • 52
  • 94

4 Answers4

4

Yes, From the Form you are trying to pass an String value to the Business layer method returnTicket(collection b). But in this Business layer method returnTicket(collection b) signature has the collection type argument to be accepted. After selecting the value from the dropdown, the selected value is stored in the string variable. Please change the collection type of the BLL and DAL's method to the string type. This change will resolve the above error.

senthil
  • 65
  • 4
  • 15
  • While this does work, it will break other code that already calls `GetTicket(collection b)` or `returnTicket(collection b)`. – Shaun Luttin Apr 22 '15 at 17:45
3

You need to pass string type argument to returnTicket of BLL and GetTicket of DAL.Change your methods like this

BLL

public string returnTicket(string supportRef)
{
   try
   {
       string ticket = DAL.data.GetTicket(supportRef);
       return ticket;
   }
   catch (Exception ex)
   {
       throw ex;
   }
}

DAL

public static string GetTicket(string supportRef)
{
 try
 {

    string returnValue = string.Empty;
    DB = Connect();
    DBCommand = connection.Procedure("getTicket");
    DB.AddInParameter(DBCommand, "@SupportRef", DbType.String, supportRef);

    var myReader = DBCommand.ExecuteReader();
    while (myReader.Read())
    {
        returnValue = myReader.GetString(0);
    }

    return returnValue;
 }


 catch (Exception ex)
 {
    throw ex;
 }

}
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40
  • While this does work, it will break other code that already calls `GetTicket(collection b)` or `returnTicket(collection b)`. – Shaun Luttin Apr 22 '15 at 17:29
2

Short Answer

In your presentation layer, map the string type into the DAL.collection type. You can see this here.

protected void ddl_Customers_SelectedIndexChanged(object sender, EventArgs e)
{
    string selectedValue = ddl_Customers.SelectedValue.ToString();

    // map the string to a DAL.collection
    var collection = new DAL.collection();
    collection.SupportRef1 = selectedValue;

    //populate the text boxes
    txtSupportRef.Text = bobj.returnTicket(collection);
}

Explanation

Both of the errors are compilation errors. You can see a recreation of them both in this fiddle.

Error 1

The best overloaded method match for 'BLL.business.returnTicket(DAL.collection)' has some invalid arguments

The compiler is trying to find a method called BLL.business.returnTicket that takes a single argument. In the match that it finds, the method takes a single DAL.collection argument. You're passing it a string instead, which is an invalid argument, because a string is not a DAL.collection. From MSDN:

Overload resolution is a compile-time mechanism for selecting the best function member to invoke given an argument list and a set of candidate function members.

Error 2

Argument 1: cannot convert from 'string' to 'DAL.collection'

Since BLL.business.returnTicket takes a DAL.collection argument, the compiler tries to convert the string into a DAL.collection. It fails because there is no implicit conversion from a string type to a DAL.collection type. From MSDN:

Implicit conversions: No special syntax is required because the conversion is type safe and no data will be lost.

What to do?

There are a few approaches you could take, in order of complexity.

  1. In your presentation layer, map the string type to the DAL.collection type. Recommended.

  2. In your business layer, create a new returnTicket(string) method overload, in addition to the existing one, which maps the string to the DAL.collection class. Recommended.

  3. Change both returnTicket(DAL.collection) and GetTicket(DAL.collection) to take a string instead of a DAL.collection. This has two downsides: it will break other code that currently calls those methods with a DAL.collection argument and it requires changing four lines of code in two different methods.

  4. Create a user-defined conversion from string into DAL.collection. Downside: this is likely overkill.

Recommended things to do

In your presentation layer, convert or to map the string type into the DAL.collection type. That is what the short answer above accomplishes.

Alternatively, in your business layer, create a new returnTicket(string) method overload, in addition to the existing method. It would look like this.

public string returnTicket(collection b)
{
     // map the string to a DAL.collection
     var collection = new DAL.collection();
     collection.SupportRef1 = selectedValue;

     // call the existing method that takes a DAL.collection
     returnTicket(b);
}
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
1

You are passing a string from Presentation Layer. Try passing the collection in presentation layer.

Harsha KN
  • 93
  • 10