我正在尝试进行更新,以便可以将 XML 文件中的数据上传到 SQL Server。但是,会引发以下异常Must declare the scalar variable...
。我想我已经声明了所需的变量。我已经检查了大约 10 次,但我看不出哪里出错了。你能?如果是,请提供对我的代码的编辑以及答案和我哪里出错的解释。感谢您的帮助和您的时间。
sqltext="SET IDENTITY_INSERT HomeCareVisit ON update HomeCareVisit set PatientNo=@PatientNo,ScheduledDateTime= @ScheduledDateTime,TreatmentInstructions=@TreatmentInstructions, MedicalStaffID=@MedicalStaffID, Priority=@Priority,ActualVisitDateTime=@ActualVisitDateTime,TreatmentProvided=@TreatmentProvided,Prescription=@Prescription,AdvisoryNotes=@AdvisoryNotes,FurtherVisitRequired=@FurtherVisitRequired where VisitRefNo=@VisitRefNo";
SqlCommand Insertcommand = new SqlCommand(sqltext, conn);
//SqlCommand Insertcommand = new SqlCommand( "SET IDENTITY_INSERT HomeCareVisit ON update HomeCareVisit set PatientNo=@PatientNo,ScheduledDateTime= @ScheduledDateTime,TreatmentInstructions=@TreatmentInstructions, MedicalStaffID=@MedicalStaffID, Priority=@Priority,ActualVisitDateTime=@ActualVisitDateTime,TreatmentProvided=@TreatmentProvided,Prescription=@Prescription,AdvisoryNotes=@AdvisoryNotes,FurtherVisitRequired=@FurtherVisitRequired where VisitRefNo=@VisitRefNo");
adpter.InsertCommand = Insertcommand;
adpter.InsertCommand.ExecuteNonQuery();
try
{
using (Insertcommand)
{
Insertcommand.Parameters.AddWithValue("@PatientNo", PatientNo);
Insertcommand.Parameters.AddWithValue("@FurtherVisitRequired", FurtherVisitRequired);
Insertcommand.Parameters.AddWithValue("@AdvisoryNotes", AdvisoryNotes);
Insertcommand.Parameters.AddWithValue("@Prescription", Prescription);
Insertcommand.Parameters.AddWithValue("@TreatmentProvided", TreatmentProvided);
Insertcommand.Parameters.AddWithValue("@ActualVisitDateTime",ActualVisitDateTime);
Insertcommand.Parameters.AddWithValue("@Priority", Priority);
Insertcommand.Parameters.AddWithValue("@ScheduledDateTime", ScheduledDateTime);
Insertcommand.Parameters.AddWithValue("@TreatmentInstructions", TreatmentInstructions);
Insertcommand.Parameters.AddWithValue("@MedicalStaffID", MedicalStaffID);
Insertcommand.ExecuteNonQuery();
MessageBox.Show("updated");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
MessageBox.Show("Done .. ");