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

更新数据库表中datetime字段
数据库表user中有字段times   ,想添加记录,代码如下:
public   int   adduser(string   id)
                {
                        SqlConnection   myconn   =   new   SqlConnection(mystring);
                        string   cmdtext   =   "insert   into   readerinfo(   id,times   )   values   ( "   +   " ' "   +   id   +   " ', "   +   " ' "   +           thetime         +   " '   ) ";
                        SqlCommand   mycommand   =   new   SqlCommand(cmdtext,   myconn);
                        int   nresult   =   -1;
                        try
                        {
                                myconn.Open();
                                nresult   =   mycommand.ExecuteNonQuery();
                        }
                        catch   (SqlException   ex)
                        {
                                throw   new   Exception(ex.Message,   ex);
                        }
                        finally
                        {
                                myconn.Close();
                        }
                        return   nresult;
                }

请问thetime   应该用什么替换?

------解决方案--------------------
DATEADD (mm, 2, getdate())
------解决方案--------------------
System.DateTime.Now.AddMonths(2)

------解决方案--------------------
用DATEADD (mm, 2, getdate())可能更好些,因为推迟的时间是和数据库服务器比对而不是和Web服务器比较