2013-08-19 2 views
0

Почему в этом коде игнорируется предложение 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 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected], 
      [email protected] 
       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); 
        }; 

        command.Parameters.AddWithValue("@TreatmentInstructions", TreatmentInstructions.Text); 
        command.Parameters.AddWithValue("@MedicalStaffID", MedicalStaffID.Text); 
        command.Parameters.AddWithValue("@VisitRefNo", VisitRefNo.Text); 
        command.ExecuteNonQuery(); 

        MessageBox.Show("Record altered"); 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
      a.Close(); 
     } 

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

      string sqlText = "select * from HomeCareVisit where VisitRefNo =" + VisitRefNo; 
      SqlCommand command = new SqlCommand(sqlText, a); 
      SqlDataReader HomeCareVisitData = command.ExecuteReader(); 

      while (HomeCareVisitData.Read()) 
      { 
       //DateTime actual = DateTime.Parse("ActualVisitDateTime"); 
       //DateTime scheduled = DateTime.Parse("ActualVisitDateTieme"); 
       PatientNo.Text = HomeCareVisitData["PatientNo"].ToString(); 
       FurtherVisitRequired.Text = HomeCareVisitData["FurtherVisitRequired"].ToString(); 
       AdvisoryNotes.Text = HomeCareVisitData["AdvisoryNotes"].ToString(); 
       Prescription.Text = HomeCareVisitData["Prescription"].ToString(); 
       TreatmentProvided.Text = HomeCareVisitData["TreatmentProvided"].ToString(); 
       ActualVisitDateTime.Text = HomeCareVisitData["ActualVisitDateTime"].ToString(); 
       Priority.Text = HomeCareVisitData["Priority"].ToString(); 
       ScheduledDateTime.Text = HomeCareVisitData["ScheduledDateTime"].ToString(); 
       TreatmentInstructions.Text = HomeCareVisitData["TreatmentInstructions"].ToString(); 
       MedicalStaffID.Text = HomeCareVisitData["MedicalStaffID"].ToString(); 
      } 
      a.Close(); 
     } 
    } 
} 
+1

предложение: Вы могли бы вырезать много полевых заданий, не затрагивая реальную проблему, делая ваш вопрос легче читать. – catfood

ответ

8

WHERE VisitRefNo=VisitRefNo"; должен быть WHERE [email protected]";.

+0

Ударьте меня! : D – clamchoda

+0

Благодарю вас за помощь. –

2
WHERE VisitRefNo=VisitRefNo 

Должно быть

WHERE [email protected] 
+0

Благодарю вас за помощь. Иногда это легко для глаз, чтобы выглядеть такой маленькой ошибкой, которая имеет значение. –

+0

Вот почему уменьшение размера примера - такая полезная техника решения проблем. – catfood

Смежные вопросы