所以我有一个网格视图与复选框。 这是页面背后的代码。System.Exception:错误的语法我找不到问题
protected void BtnApproveUsers_Click(object sender, EventArgs e)
{
var num = new List<int>();
try
{
for (var i = 0; i< GvApproveUser.Rows.Count; i++)
{
var row = GvApproveUser.Rows[i];
var isChecked = ((CheckBox) row.FindControl("ChbSelect")).Checked;
if (isChecked)
{
num.Add(System.Convert.ToInt32(GvApproveUser.Rows[i].Cells[1].Text));
Authentication.ApproveUser(num, GvApproveUser.Rows.Count);
}
}
throw new Exception("The registration forms were approved.");
}
catch (Exception exception)
{
throw new Exception(exception.Message);
}
}
这是方法。
public static void ApproveUser(List<int> userIds, int rowCount)
{
using (var connection = Utils.Database.GetConnection())
try
{
for (var i = 0; i < rowCount; i++)
{
using (var command = new SqlCommand("UPGRADE [Users] SET [Role] = @role WHERE [UserID] = @userId", connection))
{
command.Parameters.AddWithValue("@role", "User");
command.Parameters.AddWithValue("@userId", userIds[i]);
command.ExecuteNonQuery();
}
}
}
catch (Exception exception)
{
throw new Exception(exception.Message);
}
}
这是个例外:
附近有语法错误 '角色'。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关该错误的更多信息以及源代码的位置。
异常详细信息:System.Exception:“角色”附近的语法不正确。
源错误:
52行:{ 53行:
线54:抛出新的异常(exception.Message); 第55行:} 第56行:
我找不到问题。请帮助。
或者,如果你不打算对它做任何事情,不要打扰它。 – cjk 2009-12-09 12:36:57