代码工作但仍然出错 [英] code working but still getting error

查看:85
本文介绍了代码工作但仍然出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码正在对记录进行一些更新。它从网格获取ID更新。我正在将INT传递给我的方法来更新记录。我的代码正在工作,虽然我仍然得到''输入字符串格式不正确。''

代码:


foreach(GridViewRow grid.Rows)

{

CheckBox chk =(CheckBox)gr.FindControl(" checkbox");

if(chk) .Checked)

{

Data + = grid.DataKey [grid.RowIndex] .value +" ;;" ;;

}

}

String [] rowValues = Data.Split('';'');


foreach(rowValues中的字符串updateValues

{

Update.UpdateUserRow(Convert.ToInt32(updateValues));

}


this正在更新在网格中选择的记录,但我收到错误

''输入字符串的格式不正确。''

任何想法为什么?

解决方案

很可能是因为最后一个'';''符号。

我猜

1; 2; 3;当你做一个分裂时结束4个元素的数组''1','''',''3'',''''(注意空元素)。


所以它会在你爆炸时爆炸尝试将其转换为Int32。


George。

" Mike" < Mi ** @ community.nospam.com在消息新闻中写道:uJ ************** @ TK2MSFTNGP03.phx.gbl ...

我有代码这是对记录进行一些更新。它从网格获取ID更新。我正在将INT传递给我的方法来更新记录。我的代码正在工作,虽然我仍然得到''输入字符串格式不正确。''

代码:


foreach(GridViewRow grid.Rows)

{

CheckBox chk =(CheckBox)gr.FindControl(" checkbox");

if(chk) .Checked)

{

Data + = grid.DataKey [grid.RowIndex] .value +" ;;" ;;

}

}

String [] rowValues = Data.Split('';'');


foreach(rowValues中的字符串updateValues

{

Update.UpdateUserRow(Convert.ToInt32(updateValues));

}


this正在更新在网格中选择的记录,但我收到错误

''输入字符串的格式不正确。''

任何想法为什么?


" Mike"< Mi ** @ community.nospam.comwrote in message

news:uJ * ************* @ TK2MSFTNGP03.phx.gbl ...


String [] rowValues = Data.Split('';'');



String [] rowValues = Data.TrimEnd('';'')。Split('';'');

- -

Mark Rae

ASP.NET MVP
http://www.markrae.net


Mike写道:


我的代码正在对记录进行一些更新。它从网格中获取ID

来更新。我正在将INT传递给我的方法以更新

记录。我的代码正在工作,虽然我仍然得到一个''输入字符串

格式不正确。''


代码:


foreach(GridViewRow row in grid.Rows)

{

CheckBox chk =(CheckBox)gr.FindControl(" checkbox") ;

if(chk.Checked)

{

Data + = grid.DataKey [grid.RowIndex] .value +" ;;" ;

}

}

String [] rowValues = Data.Split('';'');

foreach(rowValues中的字符串updateValues

{

Update.UpdateUserRow(Convert.ToInt32(updateValues));

}


这是更新在网格中选择的记录,但我是

得到错误

''输入字符串的格式不正确。''


任何id为什么?



我假设您只想更新每一行一次?使用你的代码你将会更新第一行,然后当第二行更新时,你会再次更新第一行,依此类推。如果选择了十行,那么

将更新第一行十次。


只需获取值并更新行:


foreach(grid.Rows中的GridViewRow行){

CheckBox chk =(CheckBox)gr.FindControl(" checkbox");

if(chk.Checked){

int value = int.Parse(grid.DataKey [grid.RowIndex] .value);

Update.UpdateUserRow(value); < br $>
}

}


-

G?跑Andersson

_____
http://www.guffa.com


I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I''m passing an INT to my method to update the record. My code is working though I''m still getting an ''input string was not in a correct format.''
Code:

foreach (GridViewRow row in grid.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked)
{
Data+= grid.DataKey[grid.RowIndex].value + ";";
}
}
String[] rowValues= Data.Split('';'');

foreach (string updateValues in rowValues
{
Update.UpdateUserRow(Convert.ToInt32(updateValues) );
}

this is updating the record that is selected in the grid, but I''m getting the error
''input string was not in a correct format.''
any idea why?

解决方案

Most likely because of the last '';'' symbol.
I guess
1;2;3; ends up when you do Split as a an array of 4 elements ''1'', ''2'', ''3'', '''' (notice empty element).

So it blows up when you try to convert it to Int32.

George.
"Mike" <Mi**@community.nospam.comwrote in message news:uJ**************@TK2MSFTNGP03.phx.gbl...
I have code that is doing some updating to a record. Its getting the ID to update from the Grid. I''m passing an INT to my method to update the record. My code is working though I''m still getting an ''input string was not in a correct format.''
Code:

foreach (GridViewRow row in grid.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked)
{
Data+= grid.DataKey[grid.RowIndex].value + ";";
}
}
String[] rowValues= Data.Split('';'');

foreach (string updateValues in rowValues
{
Update.UpdateUserRow(Convert.ToInt32(updateValues) );
}

this is updating the record that is selected in the grid, but I''m getting the error
''input string was not in a correct format.''
any idea why?


"Mike" <Mi**@community.nospam.comwrote in message
news:uJ**************@TK2MSFTNGP03.phx.gbl...

String[] rowValues= Data.Split('';'');

String[] rowValues= Data.TrimEnd('';'').Split('';'');
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Mike wrote:

I have code that is doing some updating to a record. Its getting the ID
to update from the Grid. I''m passing an INT to my method to update the
record. My code is working though I''m still getting an ''input string was
not in a correct format.''
Code:

foreach (GridViewRow row in grid.Rows)
{
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked)
{
Data+= grid.DataKey[grid.RowIndex].value + ";";
}
}
String[] rowValues= Data.Split('';'');

foreach (string updateValues in rowValues
{
Update.UpdateUserRow(Convert.ToInt32(updateValues) );
}

this is updating the record that is selected in the grid, but I''m
getting the error
''input string was not in a correct format.''
any idea why?

I assume that you only want to update each row once? With your code you
would update the first row, then your would update first row again when
the second row is updated, and so on. If ten rows are selected, you
would be updating the first of them ten times.

Just get the value and update the row:

foreach (GridViewRow row in grid.Rows) {
CheckBox chk = (CheckBox)gr.FindControl("checkbox");
if (chk.Checked) {
int value = int.Parse(grid.DataKey[grid.RowIndex].value);
Update.UpdateUserRow(value);
}
}

--
G?ran Andersson
_____
http://www.guffa.com


这篇关于代码工作但仍然出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆