UpdateQuery没有错误

时间:2017-02-22 17:03:14

标签: c# mysql asp.net

我可以在UpdateQuery上使用这些WinForms,现在我将其转换为ASP.NET版本并再次使用此UpdateQuery而不起作用。其他SELECTINSERTDELETE一切正常,只有更新,也没有错误。

protected void updateBtn_Click(object sender, EventArgs e) {
    DataTable dt = new DataTable();
    string sql = "UPDATE patient SET ID=?ID, NameCH=?NameCH, NameEn=?NameEn, NRIC=?IC, Tel=?Tel, Email=?Email, Sex=?Sex, Occupation=?Occupation, Married=?Married, Address=?Address, Allergies=?Allergies, LTM=?LTM, MH=?MH, Other=?Other WHERE ( 'ID'=?ID )";
    MySqlConnection con = new MySqlConnection(conStr);
    MySqlCommand cmd = new MySqlCommand(sql, con);
    cmd.Parameters.AddWithValue("?ID", ids.Text);
    cmd.Parameters.AddWithValue("?NameCH", CHName.Text);
    cmd.Parameters.AddWithValue("?NameEN", ENName.Text);
    cmd.Parameters.AddWithValue("?IC", NRIC.Text);
    cmd.Parameters.AddWithValue("?Tel", TEL.Text);
    cmd.Parameters.AddWithValue("?Email", Email.Text);
    cmd.Parameters.AddWithValue("?Sex", sex.Text);
    cmd.Parameters.AddWithValue("?Occupation", occupation.Text);
    if (married.Checked) {
        cmd.Parameters.AddWithValue("?Married", "YES");
    } else {
        cmd.Parameters.AddWithValue("?Married", "NO");
    }
    cmd.Parameters.AddWithValue("?Address", address.Text);
    cmd.Parameters.AddWithValue("?Allergies", Allergies.Text);
    cmd.Parameters.AddWithValue("?LTM", ltm.Text);
    cmd.Parameters.AddWithValue("?MH", medicalhis.Text);
    cmd.Parameters.AddWithValue("?Other", record.Text);
    con.Open();
    cmd.ExecuteNonQuery();
    con.Close();
    Response.Redirect("~/Pages/Home.aspx/Update");
}

0 个答案:

没有答案