我不明白你收到这种错误...下面你可以看到更新 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();
}
}
}
当我调试代码时...它进入 catch 并显示错误消息:'.' 附近的语法不正确......任何人都可以知道我错在哪里......如果有人更正我的代码,那就太好了这将更新数据库中的表。
非常感谢。