我正在做這個check_Clicked過程來更新一個ListView,但更新似乎無法工作後,執行cmd.ExecuteNonQuery();當我調試時,我可以看到keyId值,它是我表中正確的Id,但是由於未知原因它沒有執行更新。任何暗示爲什麼?由於執行後沒有什麼更新cmd.ExecuteNonQuery()
protected void Check_Clicked(Object sender, EventArgs e)
{
int keyId = 0;
foreach (ListViewDataItem item in ListView1.Items)
{
CheckBox MyCheckBox = (CheckBox)item.FindControl("MyCheckBox");
if (MyCheckBox.Checked)
{
keyId = Convert.ToInt32(ListView1.DataKeys[item.DataItemIndex].Value);
}
}
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.
ConnectionStrings["ConnectionString"].ConnectionString);
//======= Insert Query.
string cmdText = "UPDATE Doctor SET [email protected],[email protected],
[email protected],[email protected] WHERE [email protected]";
SqlCommand cmd = new SqlCommand(cmdText, con);
cmd.Parameters.AddWithValue("@clientName", Convert.ToString(Session["nom"]));
cmd.Parameters.AddWithValue("@isAvailable", "False");
cmd.Parameters.AddWithValue("@apointementId", keyId);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
con.Close();
ListApointement();
}
private void ListApointement()
{
using (ListApointementDataContext db = new ListApointementDataContext())
{
var aptItems = from ListApointement in db.ListApointement select ListApointement;
ListView1.DataSourceID = null;
ListView1.DataSource = aptItems;
ListView1.DataBind();
};
}
進入調試並粘貼SQL,它在那裏工作? –
'aptItems' vs'rdvItems'? –
看起來像很多缺少的參數給我... – ganders