3层架构c#。

时间:2012-07-22 15:57:50

标签: c# asp.net implicit-conversion tableadapter 3-tier

我的3层架构存在问题。由于从对象到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);

   }

错误

enter image description here

4 个答案:

答案 0 :(得分:2)

如果ScalarQuery在引擎盖下返回int,那么:

return (int)Adapter.ScalarQuery(ManufacturerID);

但它可能会返回一个字符串,所以你需要

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

答案 1 :(得分:0)

试试这个:

  return (int)Adapter.ScalarQuery(ManufacturerID);

或者这个:

  public object countPlayer (int ManufacturerID)

答案 2 :(得分:0)

请转换Adapter.ScalarQuery(ManufacturerID);到int

答案 3 :(得分:0)

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

int playerCount=0;

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

if(success)
return playerCount;
else
//handle when parsing failed