public static List<bookstockModel> BookSearchByBookName(string searchkeyword) { List<bookstockModel> modellist = new List<bookstockModel>(); try { string sqlstring = "select * from bookstock where BookName like '%" + searchkeyword + "%'"; SqlDataReader sqlreader = CommonDB.ExecuteReader(CommonDB.CONN_STRING, CommandType.Text, sqlstring, null); while (sqlreader.Read()) { double bookprice = -1; double.TryParse(sqlreader["BookPrice"].ToString(), out bookprice); bookstockModel model = new bookstockModel(sqlreader["BookID"].ToString(), sqlreader["BookName"].ToString(), sqlreader["BookAuthor"].ToString(), sqlreader["BookPress"].ToString(), bookprice, sqlreader["BookSummary"].ToString()); modellist.Add(model); } } catch (Exception ex) { Console.WriteLine("BookSearchByBookName error!"); } return modellist; }
public static List<bookstockModel> GetModelList() { List<bookstockModel> modellist = new List<bookstockModel>(); string sqlstring = "select * from bookstock"; SqlDataReader datareader = CommonDB.ExecuteReader(CommonDB.CONN_STRING, CommandType.Text, sqlstring, null); while (datareader.Read()) { double price = -1; double.TryParse(datareader["BookPrice"].ToString(), out price); bookstockModel model = new bookstockModel(datareader["BookID"].ToString(), datareader["BookName"].ToString(), datareader["BookAuthor"].ToString() , datareader["BookPress"].ToString(), price, datareader["BookSummary"].ToString()); modellist.Add(model); } return modellist; }