c# - 使用 C# 中的应用程序在 SQL Server 中丢失数据
问题描述
我在 SQL Server 中有一个数据库,我正在使用 C# 中的应用程序插入数据。
问题是,当我插入数据时,数据没有存储在右列中。
这是我的代码:
command.CommandText = "INSERT INTO pointagee (Nom_employe, Date_Heure , Matin, Midi, apresmidi, Soir) VALUES ( ? , ? , ? , ?, ?, ?);";
command.Parameters.AddWithValue("nom", nom_employe);
command.Parameters.AddWithValue("date", date_heure);
if (matin == null)
{
command.Parameters.AddWithValue("matin", "NULL");
}
else
{
command.Parameters.AddWithValue("matin", matin);
}
if (midi == null)
{
command.Parameters.AddWithValue("midi", "NULL");
}
else
{
command.Parameters.AddWithValue("midi", midi);
}
if (Apresmidi == null)
{
command.Parameters.AddWithValue("apresmidi", "NULL");
}
else
{
command.Parameters.AddWithValue("apresmidi", Apresmidi);
}
if (Soir == null)
{
command.Parameters.AddWithValue("soir", "NULL");
}
else
{
command.Parameters.AddWithValue("soir", Soir);
}
这是数据库中的一个示例:
这些是列:
ID_employe Nom_employe Date_Heure Matin Midi apresmidi Soir
1 26/02/2020 henry 26/02/2020 12:12:12 NULL NULL
由于这个问题,这会丢失一个 NULL 值。
解决方案
推荐阅读
- python - Django psycopg2.errors.StringDataRightTruncation:对于类型字符变化的值太长(200)
- c# - 在整个应用程序中都有可用的位图
- matplotlib - matplotlib 中的 X 刻度轴
- java - Mac OS X Big Sur 上 webstart 的 JDialog 全屏问题
- jquery - 页面滚动时动态更改样式
- flutter - 对话框的动画背景颜色
- javascript - 我该如何:将所有 js 文件导入 html 或找出我需要从引导程序中折叠哪些 js 文件才能工作?
- python - 如何执行条件计算
- javascript - 如何在Angular中打开多个模式?
- r - 更改 R 中变量的类别:警告消息