Реализовал возможность записи null значений в бд

This commit is contained in:
Никита Потапов 2024-05-16 22:45:48 +04:00
parent 86565351c1
commit cbd3383e0c
3 changed files with 4 additions and 4 deletions

View File

@ -126,7 +126,7 @@ namespace MedicalPostgresqlDatabase
foreach (var key in dict.Keys)
{
cmd.Parameters.AddWithValue($"@{key}", dict[key]);
cmd.Parameters.AddWithValue($"@{key}", dict[key] ?? DBNull.Value);
}
_logger.LogDebug(cmd.CommandText);
Stopwatch stopwatch = new();
@ -167,7 +167,7 @@ namespace MedicalPostgresqlDatabase
foreach (var key in dict.Keys)
{
cmd.Parameters.AddWithValue($"@{key}", dict[key]);
cmd.Parameters.AddWithValue($"@{key}", dict[key] ?? DBNull.Value);
}
_logger.LogDebug(cmd.CommandText);

View File

@ -17,7 +17,7 @@ namespace MedicalPostgresqlDatabase.Storages
Id = Convert.ToInt32(reader.GetValue(PRIMARY_KEY_COLUMN_NAME)),
PatientId = Convert.ToInt32(reader.GetValue("patient_id")),
DoctorId = Convert.ToInt32(reader.GetValue("doctor_id")),
DiagnoseId = Convert.ToInt32(reader.GetValue("diagnose_id")),
DiagnoseId = reader.GetValue("diagnose_id") is DBNull ? null : Convert.ToInt32(reader.GetValue("diagnose_id")),
Comment = Convert.ToString(reader.GetValue("comment")),
Date = DateOnly.FromDateTime(Convert.ToDateTime(reader.GetValue("date"))),
Time = TimeOnly.FromTimeSpan((TimeSpan)reader.GetValue("time")),

View File

@ -88,7 +88,7 @@ namespace MedicalView.Visits
comboBoxDoctor.SelectedIndex = -1;
comboBoxDiagnose.DataSource = diagnoses;
comboBoxDiagnose.SelectedIndex = diagnoses.FindIndex(x => x.Name == "Первичный прием");
comboBoxDiagnose.SelectedIndex = -1;
if (ModelId.HasValue)
{