我正在嘗試進行更新,以便我可以將數據從XML文件上載到SQL Server。但是,拋出以下異常Must declare the scalar variable...
。我想我已經聲明瞭所需的變量。我查了大概10次,但是我看不出我出錯的地方。你可以嗎?如果是的話,請提供我的代碼編輯和答案,並解釋我出錯的地方。感謝您的幫助和您的時間。如何聲明一個標量變量?
sqltext="SET IDENTITY_INSERT HomeCareVisit ON update HomeCareVisit set [email protected],ScheduledDateTime= @ScheduledDateTime,[email protected], [email protected], [email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected]";
SqlCommand Insertcommand = new SqlCommand(sqltext, conn);
//SqlCommand Insertcommand = new SqlCommand("SET IDENTITY_INSERT HomeCareVisit ON update HomeCareVisit set [email protected],ScheduledDateTime= @ScheduledDateTime,[email protected], [email protected], [email protected],[email protected],[email protected],[email protected],[email protected],[email protected] where [email protected]");
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 .. ");
它告訴你你需要聲明哪個標量變量? – McKay
@PatientNo但是從代碼中可以看出它是我聲明的第一個。 –
你是說錯誤信息是@PatientNo變量沒有被聲明? – McKay