我正在从日期选择器中保存数据库中的日期。
uj["datum"] = dpDatum.SelectedDate;
[http://i59.tinypic.com/211ujk3.png][1]
SqlDataAdapter da = new SqlDataAdapter("select h.neve, f.neve,datum, tol,ig from foglalas f,helyszin h where f.helyszin_id=h.ID and f.helyszin_id=" +
(cbSzur.SelectedIndex + 1) + " and f.datum> @search ", c1);
da.SelectCommand.Parameters.AddWithValue("@search", dpSzur.SelectedDate);
当我想要取回日期时,我会得到这种格式dd/mm/yy hh/mm/ss AM
但我只想要这种格式dd/mm/yy
我如何解决这个问题?
添加到数据网格
SqlDataAdapter da = new SqlDataAdapter("select h.neve as Helyiség, f.neve as Fellépő,datum, tol,ig from foglalas f,helyszin h where f.helyszin_id=h.ID and f.helyszin_id=" +
(cbSzur.SelectedIndex + 1) + " and f.datum> @search ", c1);
da.SelectCommand.Parameters.AddWithValue("@search", ((DateTime)dpSzur.SelectedDate).ToString("yyyy-MM-dd"));
DataSet ds = new DataSet();
da.Fill(ds, "lista");
dLista.ItemsSource = ds.Tables["lista"].DefaultView;
答案 0 :(得分:0)
你可以自己格式化〜
((DateTime)dpSzur.SelectedDate).ToString("dd/MM/yy");
答案 1 :(得分:0)
一种方法是更改sql查询以返回所需格式的日期:
SqlDataAdapter da = new SqlDataAdapter("select h.neve as Helyiség, f.neve as Fellépő,CONVERT(VARCHAR(10),datum,110), tol,ig from foglalas f,helyszin h where f.helyszin_id=h.ID and f.helyszin_id=" +
(cbSzur.SelectedIndex + 1) + " and f.datum> @search ", c1);
有关格式列表,请参阅this链接