From ff0b60f3bd20218e07b15c400898b1adf735dc1f Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 8 May 2024 09:39:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=BE=D0=BD=D0=BA=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B2=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Storages/DiagnosesStorage.cs | 8 ++++---- .../MedicalPostgresqlDatabase/Storages/DoctorsStorage.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Medical/MedicalPostgresqlDatabase/Storages/DiagnosesStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/DiagnosesStorage.cs index dbfd10a..9c64896 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/DiagnosesStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/DiagnosesStorage.cs @@ -17,8 +17,8 @@ namespace MedicalPostgresqlDatabase.Storages { return new Diagnose { - Id = reader.GetInt32(0), - Name = reader.GetString(1), + Id = Convert.ToInt32(reader.GetOrdinal(PRIMARY_KEY_COLUMN_NAME)), + Name = Convert.ToString(reader.GetOrdinal("name")), }; } @@ -26,7 +26,7 @@ namespace MedicalPostgresqlDatabase.Storages { using var connection = GetConnection(); connection.Open(); - using var cmd = new NpgsqlCommand("INSERT INTO diagnoses (diagnose_id, name) VALUES ((nextval('diagnoses_id_seq')), @name)", connection); + using var cmd = new NpgsqlCommand($"INSERT INTO diagnoses ({PRIMARY_KEY_COLUMN_NAME}, name) VALUES ((nextval('diagnoses_id_seq')), @name)", connection); cmd.Parameters.AddWithValue("@name", item.Name); Stopwatch stopwatch = new(); stopwatch.Start(); @@ -39,7 +39,7 @@ namespace MedicalPostgresqlDatabase.Storages { using var connection = GetConnection(); connection.Open(); - using var cmd = new NpgsqlCommand("UPDATE diagnoses SET name = @name WHERE diagnose_id = @id", connection); + using var cmd = new NpgsqlCommand($"UPDATE diagnoses SET name = @name WHERE {PRIMARY_KEY_COLUMN_NAME} = @id", connection); cmd.Parameters.AddWithValue("@id", item.Id); cmd.Parameters.AddWithValue("@name", item.Name); Stopwatch stopwatch = new(); diff --git a/Medical/MedicalPostgresqlDatabase/Storages/DoctorsStorage.cs b/Medical/MedicalPostgresqlDatabase/Storages/DoctorsStorage.cs index 0d68d07..339d376 100644 --- a/Medical/MedicalPostgresqlDatabase/Storages/DoctorsStorage.cs +++ b/Medical/MedicalPostgresqlDatabase/Storages/DoctorsStorage.cs @@ -30,7 +30,7 @@ namespace MedicalPostgresqlDatabase.Storages { using var connection = GetConnection(); connection.Open(); - using var cmd = new NpgsqlCommand("INSERT INTO doctors (doctor_id, name, surname, patronymic, phone_number, specialization_id) VALUES ((nextval('doctors_id_seq')), @name, @surname, @patronymic, @phone_number, @specialization_id)", connection); + using var cmd = new NpgsqlCommand($"INSERT INTO doctors ({PRIMARY_KEY_COLUMN_NAME}, name, surname, patronymic, phone_number, specialization_id) VALUES ((nextval('doctors_id_seq')), @name, @surname, @patronymic, @phone_number, @specialization_id)", connection); cmd.Parameters.AddWithValue("@name", item.Name); cmd.Parameters.AddWithValue("@surname", item.Surname); cmd.Parameters.AddWithValue("@patronymic", item.Patronymic);