我没有使用日期时间作为我的桌子的价值但我想知道为什么时间仍然出现:
以下是获取gridview输出的代码:
private void CalendarDataGrid()
{
con.Open();
cmd = new SqlCommand(@"SELECT StocksHistory.DateTrack,Stocks.ItemID
,StocksHistory.StockIn,StocksHistory.StockOut
,StocksHistory.StockOnHand
FROM Stocks
FULL OUTER JOIN StocksHistory
ON Stocks.ItemID = StocksHistory.ItemID
WHERE DateTrack between @date1 and @date2", con);
cmd.Parameters.AddWithValue("@date1",txtDate1.Text);
cmd.Parameters.AddWithValue("@date2",txtDate2.Text);
da = new SqlDataAdapter(cmd);
dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
我怎样才能获得日期?
答案 0 :(得分:1)
我找到了解决方案。 Reference
<asp:BoundField HeaderText="Date"
DataField="SampleDate"
DataFormatString="{0:MM/dd/yyyy}" >
答案 1 :(得分:0)
"SELECT cast(StocksHistory.DateTrack as date),Stocks.ItemID
,StocksHistory.StockIn,StocksHistory.StockOut
,StocksHistory.StockOnHand
FROM Stocks
FULL OUTER JOIN StocksHistory
ON Stocks.ItemID = StocksHistory.ItemID
WHERE DateTrack between @date1 and @date2"
答案 2 :(得分:0)
您只需更新内联SQL即可。 通过CAST(StocksHistory.DateTrack AS DATE)AS DateTrack或CONVERT(DATE,StocksHistory.DateTrack)AS DateTrack替换StocksHistory.DateTrack。