command.Parameters.Add("@Birthday", OleDbType.Date).Value = this.birthday;
我想当 this.birthday = DateTime.MinValue 时不要插入MinValue,而是插入时保持该字段为空怎样才行?

解决方案 »

  1.   

    if ( this.birthday != DateTime.MinValue )
    {
    command.Parameters.Add("@Birthday", OleDbType.Date).Value = this.birthday;
    }
      

  2.   

    string sqlInsert = "insert into MyTable (Birthday) values (@Birthday)"
    OleDbConnection connection = Data.GetOleDbConnection();
    OleDbCommand command = new OleDbCommand(sqlInsert, connection);
    if ( this.birthday != DateTime.MinValue ) {
       command.Parameters.Add("@Birthday", OleDbType.Date).Value =this.birthday;
    }
    /*
     * 如果这样就提示参数没有值
     * 我想当this.birthday = DateTime.MinValue时也插入一条但记录,没没有值显示出来。用连接字符串时可以用insert MyTable values (null) */