所以我有一个带有复选框的网格视图.这是页面背后的代码.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是方法.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是例外:
"角色"附近的语法不正确.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.Exception:"Role"附近的语法不正确.
来源错误:
第52行:{第53行:
第54行:抛出新的异常(exception.Message); 第55行:}第56行:
我找不到问题.请帮忙.