Search code examples
c#asp.netimplicit-conversiontableadapter3-tier

3 Tier Architecture c#.


I having problems with my 3 tier architecture. It seems that I could not count the number of players due to implicit conversion from object to Int.

DropDownList

protected void ddlManufacturer_SelectedIndexChanged(object sender, EventArgs e)
{
    BLLPlayer playerBLL = new BLLPlayer();

 Label1.Text =  playerBLL.countPlayer(Convert.ToInt32(ddlManufacturer.SelectedValue)).ToString();
}

BLLPlayer

public int countPlayer (int ManufacturerID)
   {

   return Adapter.ScalarQuery(ManufacturerID);

   }

ERROR

enter image description here


Solution

  • if ScalarQuery returns int under the hood then:

    return (int)Adapter.ScalarQuery(ManufacturerID);
    

    But it might return a string so you need

    return Convert.ToInt32(Adapter.ScalarQuery(ManufacturerID));