简体   繁体   中英

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

在此输入图像描述

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));

Try this:

  return (int)Adapter.ScalarQuery(ManufacturerID);

or this:

  public object countPlayer (int ManufacturerID)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM