我不明白我收到這種錯誤...下面你可以看到更新sqlquery。更新獲取錯誤在捕獲異常和消息是在說明
protected void btnupdate_Click(object sender, EventArgs e)
{
string pID = Convert.ToString(Session["PatientId"]);
if (!string.IsNullOrEmpty(pID))
{
int patientID = Convert.ToInt32(pID);
SqlConnection connew = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("Upadate [dbo].[PatientDetails] set [title] = @pttit, [sex] = @ptgen, [lastname] = @ptlastnm, " +
" [birthday] = @ptbirth, [firstname] = @ptfirstnm, [middlename] = @ptmiddlenm, [remarkline] = @ptremarkln, [remarks] = @ptremark " +
"where [PatientId] = '"+pID+"'", connew);
cmd.Parameters.AddWithValue("@pttit", txtpttitle.Text);
cmd.Parameters.AddWithValue("@ptgen", txtgender.Text);
cmd.Parameters.AddWithValue("@ptlastnm", txtptlastnm.Text);
cmd.Parameters.AddWithValue("@ptbirth", txtptbirthday.Text);
cmd.Parameters.AddWithValue("@ptfirstnm", txtptfirstnm.Text);
cmd.Parameters.AddWithValue("@ptmiddlenm", txtptmiddlenm.Text);
cmd.Parameters.AddWithValue("@ptremarkln", txtptremarkline.Text);
cmd.Parameters.AddWithValue("@ptremark", txtremarks.Text);
cmd.CommandType = CommandType.Text;
cmd.Connection = connew;
if (connew.State == ConnectionState.Closed)
{
connew.Open();
}
try
{
//rowsaffected = cmd.ExecuteNonQuery();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write("Error Occured: " + ex.Message.ToString());
}
finally
{
connew.Close();
cmd.Dispose();
}
}
}
當我調試的代碼......它進入捕捉並顯示錯誤消息:附近有語法錯誤.'....有誰能夠有地方我錯了....它會想法如果有人糾正我的代碼將更新數據庫中的表,那就太好了。
非常感謝。
在這種情況下使用'存儲過程'不是更容易嗎? –