我对日期有疑问。我无法使该.AddYears()
方法起作用。有人可以看看我在这里做错了什么。
MySqlConnection myMySqlConnection = new MySqlConnection(connectionString);
MySqlDataAdapter da = new MySqlDataAdapter();
MySqlCommand cmd1;
cmd1 = new MySqlCommand("SELECT INITIAL_DATE FROM USERS WHERE ID = @id1", myMySqlConnection);
cmd1.Parameters.AddWithValue("@id1", id);
myMySqlConnection.Open();
da.SelectCommand = cmd1;
DateTime initial_date = (DateTime)cmd1.ExecuteScalar();
myMySqlConnection.Close();
从这一点及以下是问题:
DateTime[] dates = new DateTime[20];
dates[0] = Convert.ToDateTime(initial_date);
for (int i = 1; i < 20; i++)
{
dates[i] = initial_date.AddYears(1);
}