我有一个 UPDATE 存储过程,它适用于 SQL Server 查询:
GO
ALTER PROCEDURE [dbo].[UpdateMedicalCard]
@RecordingCode int,
@BeginTreatmentDate date,
@EndTreatmentDate date,
@MainDiagnosis nchar(100),
@AttendantDiagnosis nchar(100),
@TreatmentResult nchar(50)
AS
BEGIN
UPDATE MedicalCard
SET BeginTreatmentDate = @BeginTreatmentDate,
EndTreatmentDate = @EndTreatmentDate,
MainDiagnosis = @MainDiagnosis,
AttendantDiagnosis = @AttendantDiagnosis,
TreatmentResult = @TreatmentResult
WHERE RecordingCode = @RecordingCode
END
但是当我从 Visual Studio 调用此过程时,它不会更新。
SqlConnection connection = new SqlConnection();
connection.ConnectionString = @"Data Source=.;Initial Catalog=Policlinic;Integrated Security=SSPI";
connection.Open();
SqlCommand myCommand = connection.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "UpdateMedicalCard";
myCommand.Parameters.Add("@RecordingCode", System.Data.SqlDbType.Int);
myCommand.Parameters["@RecordingCode"].Value = dataGridView1.CurrentRow.Cells[0].Value;
myCommand.Parameters.Add("@BeginTreatmentDate", System.Data.SqlDbType.Date);
myCommand.Parameters["@BeginTreatmentDate"].Value = dataGridView1.CurrentRow.Cells[3].Value;
myCommand.Parameters.Add("@EndTreatmentDate", System.Data.SqlDbType.Date);
myCommand.Parameters["@EndTreatmentDate"].Value = dataGridView1.CurrentRow.Cells[4].Value;
myCommand.Parameters.Add("@MainDiagnosis", System.Data.SqlDbType.NChar);
myCommand.Parameters["@MainDiagnosis"].Value = "qwe";
myCommand.Parameters.Add("@AttendantDiagnosis", System.Data.SqlDbType.NChar);
myCommand.Parameters["@AttendantDiagnosis"].Value = dataGridView1.CurrentRow.Cells[6].Value;
myCommand.Parameters.Add("@TreatmentResult", System.Data.SqlDbType.NChar);
myCommand.Parameters["@TreatmentResult"].Value = dataGridView1.CurrentRow.Cells[7].Value;
var dataAdapter = new SqlDataAdapter(myCommand);
var dataTable = new DataTable();
dataAdapter.Update(dataTable);
connection.Close();
我想我在最后 4 行做错了。请帮忙。