我想让日期([date],Datetime 类型,格式如:2008-6-10)早于今天的记录的[readtype] 字段的值为‘old’,日期为今天的[readtype] 字段值设为‘new’,咋整呢,用下面的语句不行啊。
UPDATE [news] SET [readtype] = 'old' WHERE [date] <>" + DateTime.Today.ToShortDateString();
一运行全部变成old,
这句
AccessDataSource1.UpdateCommand = "UPDATE [news] SET [readtype] = 'new' WHERE [date] =" + DateTime.Today.ToShortDateString();
没有一个变为‘new’的。但实际上有[date]字段的值和DateTime.Today.ToShortDateString()的值是相等的啊。

解决方案 »

  1.   

    UPDATE [news] SET [readtype] = 'old' WHERE [date] < 你传递的时间值
      

  2.   

    需要都转成字符型,
    不要用 ToShortDateString,它好像六月是用'6'而为是'06'substring(convert(nvarchar(100),getdate(),20),1,10)  ---sqlstring s=DateTime.Today.ToString("yyyy-MM-dd");    //C#
      

  3.   

    DateTime.Today.ToShortDateString()是string型的。。
    UPDATE [news] SET [readtype] = 'new' WHERE datediff(d,date,getdate())=0
      

  4.   

    update [news] set [readtype]='old' where datediff(dd,getdate(),[date])<0
      

  5.   


    string today = DateTime.Now.ToString("yyyy-MM-dd");
    "UPDATE [news] SET [readtype] = 'old' WHERE [date] <" + today; 
    "UPDATE [news] SET [readtype] = 'new' WHERE [date] >=" + today; 
      

  6.   

    update [news] set [readtype]='old' where datediff(day,[date],getdate()) >0update [news] set [readtype]='new' where datediff(day,[date],getdate()) =0
      

  7.   

    不要用<>和=
    这样就只能和当天的0点比较,
    如2008-06-10 0:00:00 而2008-06-10其他时间就和这个时间都不相等了,所以都是old
      

  8.   

    一个是datetime 一个是string 当然不等于
      

  9.   

    create table ceshi(dt datetime,readtype varchar(10))create trigger tri_ceshi
    on ceshi
    for insert
    as
    begin
    update tp set readtype=case when datediff(dd,dt,getdate())=0 then '新' else '旧' end from ceshi tp
    endinsert into ceshi(dt) select getdate()
    insert into ceshi(dt) select '2008-06-09 16:00:25.340'select * from ceshidrop table ceshidt readtype
    2008-06-10 16:04:14.467 新
    2008-06-09 16:00:25.340 旧触发器
      

  10.   

    从数据库查询出来的时候用这个查询  Convert(char(10),GetDate(),120)然后从界面 获取字符串后在截取字符串 string s=DateTime.Today.ToString("yyyy-MM-dd");时间可以用> 或< 等的比较的    
      

  11.   

    从数据库查询出来的时候用这个查询  Convert(char(10),GetDate(),120)然后从界面 获取字符串后在截取字符串 string s=DateTime.Today.ToString("yyyy-MM-dd");时间可以用> 或< 等的比较的    
      

  12.   

    我用的是access 数据库,不能用getdate()这个函数。
    以上方法都没有达到我要的效果。
      

  13.   

    呵呵,自己已经想办法搞定了。html code:<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/xmdata.mdb" UpdateCommand="UPDATE [news] SET [readtype] = 'old' WHERE [date] <> ?" >
            <UpdateParameters>
                <asp:ControlParameter ControlID="dttm" Name="date" PropertyName="Value" Type="dateTime" />
                        </UpdateParameters></asp:AccessDataSource>
        <asp:HiddenField ID="dttm" runat="server" Value="" />
    C# code:protected void Page_Load(object sender, EventArgs e)
        {        
            dttm.Value = DateTime.Today.ToShortDateString();
            AccessDataSource1.Update();
            AccessDataSource1.UpdateCommand = "UPDATE [news] SET [readtype] = 'new' WHERE [date] = ?";
            AccessDataSource1.Update();    }