我真的很生气,c#怎么可能没有简单的日期格式,没有在那之后的恼人时间
这是我的问题:
我有一堂课
public class Dates
{
// private int excursionID;
private int excursion_date_ID;
private DateTime startdates;
private double prices;
/* public int ExcursionID
{
get { return excursionID; }
set { excursionID = value; }
}*/
public int Excursion_date_ID
{
get { return excursion_date_ID; }
set { excursion_date_ID = value; }
}
public DateTime StartDates
{
get { return startdates.Date; }
set { startdates = value.Date; }
}
public double Prices
{
get { return prices; }
set { prices = value; }
}
public Dates() { }
}
}
然后在 PageLoad 我从数据库中获取一些数据
public List<Dates> GetDates()
{
List<Dates> datesList = new List<Dates>();
string connectionString = "Server=localhost\\SQLEXPRESS;Database=excursion;Trusted_Connection=true";
string excursionnID = Request.QueryString["ExcursionID"];
string query =
"SELECT Excursion_date_ID, Start_date, Price FROM EXCURSION_DATES WHERE EXCURSION_ID='" + excursionnID + "'";
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(query, conn);
try
{
conn.Open();
SqlDataReader rd = cmd.ExecuteReader();
int s=0;
while (rd.Read())
{
Dates dates = new Dates();
// dates.ExcursionID = Convert.ToInt32(rd["Excursion_ID"]);
dates.Excursion_date_ID=Convert.ToInt32(rd["Excursion_date_ID"]);
DateTime excursiondatetime = (DateTime)rd["Start_date"];
dates.StartDates = excursiondatetime.Date;
dates.Prices = Convert.ToDouble(rd["Price"]);
datesList.Add(dates);
}
}
catch (Exception EX)
{
}
return datesList;
}
然后我只返回填充一个 GridView,返回列表是我的 Page_Load
Dates date = new Dates();
List<Dates> listDate = new List<Dates>();
listDate = GetDates();
gvDates.DataSource = listDate;
gvDates.DataBind
现在有人可以解释为什么当你看到我只得到日期部分时我一直得到小时部分