public void SetMaxPaging(ForPaging Paging, string Search, string Account) { //計算列數 int Row = 0; string sql = $@" SELECT * FROM Article WHERE ( Title LIKE '%{Search}%' OR Content LIKE '%{Search}%' ) AND Account = '{Account}'; "; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Row++; } } catch (Exception e) { throw new Exception(e.Message.ToString()); } finally { conn.Close(); } Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Row) / Paging.ItemNum)); Paging.SetRightPage(); }
public void SetMaxPaging(ForPaging Paging, int A_Id) { //計算列數 int Row = 0; string sql = $@" SELECT * FROM Message WHERE A_Id = {A_Id}; "; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Row++; } } catch (Exception e) { throw new Exception(e.Message.ToString()); } finally { conn.Close(); } Paging.MaxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Row) / Paging.ItemNum)); Paging.SetRightPage(); }