所以我有一個網格視圖與複選框。 這是頁面背後的代碼。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