我试图从数据库中显示我的数据。如果我今天存储了一些数据,仅此一项就应该显示在GridView
.
我希望能够按周、月和年显示。
我的代码:
public void gettoday()
{
con.Open();
{
//string strview = "select MRNO,MaterialCode,Description,Specification,Category as Cat,Source as Sor,Population as Pop, StockInStores as Stock,MRRating as Rating,PreparedBy,PreparedDate,CheckedBy,CheckedDate,ApprovedBy,ApprovedDate from tbl_KKSMaterialRaise where PreparedDate between DateAdd(day,-1,GetDate()) AND DateAdd(day,+1,GetDate())";
string strview = "select MRNO,MaterialCode,Description,Specification,Category as Cat,Source as Sor,Population as Pop, StockInStores as Stock,MRRating as Rating,PreparedBy,PreparedDate,CheckedBy,CheckedDate,ApprovedBy,ApprovedDate from tbl_KKSMaterialRaise where PreparedDate between (getdate()-1) and (getdate()+1) order by PreparedDate";
SqlCommand cmd = new SqlCommand(strview, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
//SqlDataReader reader = cd.ExecuteReader();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
con.Close();
}