asp.net string类型怎么转换成int 类型

unfish 2013-02-22 03:05:56
   protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string get = Request.QueryString["couEname"].ToString();
string[] array = get.Split('_'); //出错位置
int name = (int)array[1];
cont = Td_CountryManager.GetTd_CountryByCouName(name);
string sql = string.Format("select * from td_region where countryid={0}", name);
Repeaterdq.DataSource = Td_RegionManager.SelectAllTd_RegionsBySql(sql);
Repeaterdq.DataBind();
string qzzl = "";
sql = string.Format("select visaname from td_visa where visaregionid in(select regionid from td_region where countryid={0})and visatype=1 group by visaname", name);
DataTable table = DBHelper.GetTable(sql);
foreach (DataRow row in table.Rows)
{
qzzl += "<li><p style='width:330px;'>" + row["visaname"].ToString() + "</p> <p style='width:100px;'>" + daqu(name, row["visaname"].ToString()) + "</p></li>";
}
Literal1.Text = qzzl;

sql = string.Format("select top 10 * from td_question where countryid={0} order by questiontime desc", name);
Repeaterwt.DataSource = Td_QuestionManager.SelectAllTd_QuestionsBySql(sql);
Repeaterwt.DataBind();
sql = "select top 10 * from td_message where messagetype=5 order by messagetime desc";
Repeaterkx.DataSource = Td_MessageManager.SelectAllTd_MessagesBySql(sql);
Repeaterkx.DataBind();
Td_Kword kword = Td_KwordManager.GetTd_KwordByKwordId(2);
}
}


测试时提示“string类型无法转换成int类型。”

注:couEname是用拼音拼写的名字

各位看一下该怎么解决啊!!!
...全文
1011 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
int name = Convert.ToInt32(array[1]);
zhaowenyi713 2013-02-22
  • 打赏
  • 举报
回复
int.Parse
自律2019 2013-02-22
  • 打赏
  • 举报
回复
引用 4 楼 lye2000000_super 的回复:
int name = (int)array[1]; 换成 int name = int.Parse(array[1]); 试试看。 debug下get里面是什么内容。 还有。get是保留字吧?换个变量名吧。
可以用int.TryParse(array[1])看以下返回值,监视一下为什么出错,才能解决
sjbcl2008 2013-02-22
  • 打赏
  • 举报
回复
get是保留字吧,这最基本的吧 你换个变量名。
  • 打赏
  • 举报
回复
int name = (int)array[1]; 换成 int name = int.Parse(array[1]); 试试看。 debug下get里面是什么内容。 还有。get是保留字吧?换个变量名吧。
threenewbee 2013-02-22
  • 打赏
  • 举报
回复
int name = (int)array[1]; => int name = int.Parse(array[1]);
闭家锁sos 2013-02-22
  • 打赏
  • 举报
回复
使用convert.toInt32(需要转换的string类型),或是利用int.parmes();
夜色镇歌 2013-02-22
  • 打赏
  • 举报
回复
哪一行出错了?int是数字啊,你确定是数字么。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧