1.跟踪一下看语句执行时是不是真的插入了null?
2.默认值改成convert(smalldatetime,(convert(varchar(10),getdate(),120)))试试?

解决方案 »

  1.   

    insert into tb(字段) values(isnull((convert(varchar(10),getdate(),120))),'1900-01-01')--or
    insert into tb(字段) values(isnull(输入值),'1900-01-01')
      

  2.   


    declare @a table(id int, date datetime default (convert(varchar(10),getdate(),120)))insert into @a(id)values(1)
    insert into @a(id,date)values(1,' ')
    insert into @a(id,date)values(1,0)
    insert into @a(id,date)values(1,1)
    insert into @a(id,date)values(1,2)select * from @a
      

  3.   

    insert into wjhgxxzb values ('443453434','中外运',112,'34343543453','进口','34345354','','','','')
    最后的的确为空的。。跟踪了下。
      

  4.   

    字段设置了默认值,只有你不给这个字段赋值的时候才会使用默认值,否则使用你输入的值.
    你的可以用casedeclare @a table(id int, date datetime default (convert(varchar(10),getdate(),120)))declare @date varchar(10)
    set @date = ''
    insert into @a(id,date)
     select 1,case when ltrim(rtrim(@date))='' then convert(varchar(10),getdate(),120) else @date end
    select * from @a
      

  5.   

    楼主,你看清楚插入的时候插入''和插入null是不同概念的哦;
    我刚才做了个试验,如果我插入''那么就会变成1900-01-01,插入null就会变成getdate()
      

  6.   

    c#中的时间框中不输入,在程序里面取得应该是 string date=''
    将空白字符串插入数据库时,数据库不会使用字段默认值,这时候SQLSERVER会自动将''字符串转换为时间格式,即为1900-01-01
      

  7.   

    sorry,上面有点错了,还要看你的字段是否允许为空,如果允许为空,那么插入null的话它就真的是null了,你看看下面的执行效果:create table #test (
    id int, 
    date1 smalldatetime default convert(smalldatetime,(convert(varchar(10),getdate(),120))),
    date2 smalldatetime not null default convert(smalldatetime,(convert(varchar(10),getdate(),120)))
    )insert into #test (id) values (1)
    insert into #test (id, date1) values (2,'')
    insert into #test (id, date1) values (2,null)select * from #test1 2008-04-17 00:00:00 2008-04-17 00:00:00
    2 1900-01-01 00:00:00 2008-04-17 00:00:00
    2 NULL 2008-04-17 00:00:00
      

  8.   

    看到了。那我去把那个文本框默认赋值为NULL....试试
      

  9.   

    已经得到正解了。。插入'',,转化为1900-01-01。非常感谢。上次有个ASP的也碰到过。