0

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

Challenger
  • 251
  • 2
  • 13

4 Answers4

2

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));
Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
0

Try this:

  return (int)Adapter.ScalarQuery(ManufacturerID);

or this:

  public object countPlayer (int ManufacturerID)
Hogan
  • 69,564
  • 10
  • 76
  • 117
0

Please cast the Adapter.ScalarQuery(ManufacturerID); to int

HatSoft
  • 11,077
  • 3
  • 28
  • 43
0
return Convert.ToInt32(Adapter.ScalarQuery(ManufacturerID));

or

int playerCount=0;

var success=Int32.TryParse(Adapter.ScalarQuery(ManufacturerID), ref playerCount);

if(success)
return playerCount;
else
//handle when parsing failed
Baz1nga
  • 15,485
  • 3
  • 35
  • 61