小编Geo*_*den的帖子

为什么这会忽略where子句?

为什么在此代码中忽略where子句?它似乎忽略了更新中的where子句,这意味着每个记录都已被写入.我怎样才能解决这个问题?任何帮助将不胜感激.

namespace ResitAssignment2
{
    public partial class HomeCareVisitEddit : Form
    {
        public HomeCareVisitEddit()
        {
            InitializeComponent();
        }

        private void SubmitHCVA_Click(object sender, EventArgs e)
        {
            SqlConnection a = Database.GetConnection();
            a.Open();

            string sqltext;
            sqltext = @"update HomeCareVisit set
             PatientNo=@PatientNo,
             FurtherVisitRequired=@FurtherVisitRequired,
             AdvisoryNotes=@AdvisoryNotes,
             Prescription=@Prescription,
             TreatmentProvided=@TreatmentProvided,
             ActualVisitDateTime=@ActualVisitDateTime,
             Priority=@Priority,
             ScheduledDateTime=@ScheduledDateTime,
             TreatmentInstructions=@TreatmentInstructions,
             MedicalStaffID=@MedicalStaffID
              WHERE
             VisitRefNo=VisitRefNo";

            SqlCommand command = new SqlCommand(sqltext, a);

            try
            {
                using (a)
                {
                    command.Parameters.AddWithValue("@PatientNo", PatientNo.Text);
                    command.Parameters.AddWithValue("@FurtherVisitRequired", FurtherVisitRequired.Text);
                    command.Parameters.AddWithValue("@AdvisoryNotes", AdvisoryNotes.Text);
                    command.Parameters.AddWithValue("@Prescription", Prescription.Text);
                    command.Parameters.AddWithValue("@TreatmentProvided", TreatmentProvided.Text);
                    command.Parameters.AddWithValue("@ActualVisitDateTime",SqlDbType.DateTime );
                    {
                        DateTime.Parse(ActualVisitDateTime.Text);
                    };
                    command.Parameters.AddWithValue("@Priority", Priority.Text);
                    command.Parameters.AddWithValue("@ScheduledDateTime",SqlDbType.DateTime );
                    {
                        DateTime.Parse(ScheduledDateTime.Text);
                    }; …
Run Code Online (Sandbox Code Playgroud)

c# sql ado.net

0
推荐指数
1
解决办法
118
查看次数

标签 统计

ado.net ×1

c# ×1

sql ×1