I'm using a table LOG
which has 3 columns:
我正在使用一个包含3列的表LOG:
Login nvarchar(50)
Date int
-
Logout nvarchar(50)
Now if I don't enter a value into the Logout
column, then NULL
should be stored. But for me it is stored as " "
.
现在,如果我没有在Logout列中输入值,则应存储NULL。但对我来说它存储为“”。
I have given my table definition in screenshot 1 and the table data in screenshot 2.
我在截屏1中给出了我的表定义,在截屏2中给出了表数据。
4 个解决方案
#1
0
May be in the INSERT query you are using INSERT INTO log (Login, Date, Logout) VALUES(...) and a "" as the value for the Logout field. Check your insert statement and verify that you are not making this mistake.
可能在INSERT查询中使用INSERT INTO log(登录,日期,注销)VALUES(...)和“”作为Logout字段的值。检查您的插入语句并确认您没有犯这个错误。
#2
0
List of Alternative to solve this :
解决此问题的替代方案清单:
- Set Default Value to that Column.
- Provide NULL with out 'NULL' In Insert Query.
- Select Data if '' found then NULL. (No change during insertion)
- Update current data if '' found then set NULL.
将默认值设置为该列。
在插入查询中提供带有'NULL'的NULL。
如果''found,则选择Data,然后选择NULL。 (插入时无变化)
如果''找到然后设置为NULL,则更新当前数据。
Thanks.
#3
0
Try this code.
试试这个代码。
if (!string.IsNullOrEmpty(Impdate.ToString()))
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = Impdate;
}
else
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = SqlDateTime.Null;
}
#4
0
Try like this
试试这样吧
if (!string.IsNullOrEmpty(Impdate.ToString()))
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = Impdate;
}
else
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = "";
}
#1
0
May be in the INSERT query you are using INSERT INTO log (Login, Date, Logout) VALUES(...) and a "" as the value for the Logout field. Check your insert statement and verify that you are not making this mistake.
可能在INSERT查询中使用INSERT INTO log(登录,日期,注销)VALUES(...)和“”作为Logout字段的值。检查您的插入语句并确认您没有犯这个错误。
#2
0
List of Alternative to solve this :
解决此问题的替代方案清单:
- Set Default Value to that Column.
- Provide NULL with out 'NULL' In Insert Query.
- Select Data if '' found then NULL. (No change during insertion)
- Update current data if '' found then set NULL.
将默认值设置为该列。
在插入查询中提供带有'NULL'的NULL。
如果''found,则选择Data,然后选择NULL。 (插入时无变化)
如果''找到然后设置为NULL,则更新当前数据。
Thanks.
#3
0
Try this code.
试试这个代码。
if (!string.IsNullOrEmpty(Impdate.ToString()))
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = Impdate;
}
else
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = SqlDateTime.Null;
}
#4
0
Try like this
试试这样吧
if (!string.IsNullOrEmpty(Impdate.ToString()))
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = Impdate;
}
else
{
cmd.Parameters.Add("@Logout", SqlDbType.Date).Value = "";
}