日期:2014-05-19  浏览次数:20491 次

|M| 关于数据库表设置问题:比如 LiveDate 日期型字段要怎么来定义,是否要定义一个默认值
比如员工表中有字段LiveDate就是 "离职日期 "
当我们添加的时候LiveDate是为空的
但是我现在是用Grove这个工具来加记录的
他是要求每一个字段都是要有数据
那这个LiveDate我要赋给什么样的值呢

谢谢

------解决方案--------------------
默认值可以设置为GetDate(),表示当前日期
------解决方案--------------------
当我们添加的时候LiveDate是为空的
他是要求每一个字段都是要有数据
--------------------------------------

把这个字段设 无,不就可以了??

------解决方案--------------------
字段设置个默认值:1900-01-01 00:00:00!

------解决方案--------------------
变通一点,就用nvarchar

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
------解决方案--------------------
那还不看你要怎么要求
比如一个 很大的时间 或很早的时间 或者空
------解决方案--------------------
DateTime.MinValue
------解决方案--------------------
可空类型:
示例如下:
using System;
using System.Text;
using System.IO;
using System.Data;
using System.Diagnostics;
using System.Collections;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class ConsoleTest
{
public static void Main()
{
SqlConnection theCon = new SqlConnection();
SqlCommand theCmd = new SqlCommand();
string strCon = "Server=127.0.0.1;DataBase=TestDB;Integrated Security=SSPI ";
theCon.ConnectionString = strCon;
theCmd.Connection = theCon;
theCon.Open();
string strCmd = "INSERT INTO test VALUES(@ID,@NAME,@DATE) ";
theCmd.CommandText = strCmd;
theCmd.Parameters.Add( "@ID ", SqlDbType.Char, 1);
theCmd.Parameters.Add( "@NAME ", SqlDbType.VarChar, 10);
theCmd.Parameters.Add( "@DATE ", SqlDbType.DateTime);
theCmd.Parameters[0].Value = 'G ';
theCmd.Parameters[1].Value = "lizhizhe2000 ";
DateTime? mytime=null;
DBNull aa = System.DBNull.Value;
if (!mytime.HasValue)
theCmd.Parameters[2].Value = aa;
else
theCmd.Parameters[2].Value = mytime;
try
{
theCmd.ExecuteNonQuery();
Console.WriteLine( "OK,Close it ");
}
catch (Exception e)
{
Console.Write(e.Message);
}
finally
{
theCon.Close();
Console.ReadLine();
}

}
}
}

表结构:
CREATE TABLE [dbo].[test](
[ID] [char](1) COLLATE Chinese_PRC_CI_AS NOT NULL,
[theName] [varchar](10) COLLATE Chinese_PRC_CI_AS NULL,
[datethe] [datetime] NULL
) ON [PRIMARY]
------解决方案--------------------
设置一个时间值,初始为空,员工签退时更为非空值,然后根据这个时间值进行插入判断
------解决方案--------------------