public Baowen getBaowen(int id) { try { var sql = "select * from baowen where id=@id;"; var cmdparams = new List <SQLiteParameter>() { new SQLiteParameter("id", id) }; DataTable dt = sh.Select(sql, cmdparams); Baowen b = new Baowen(); foreach (DataRow dr in dt.Rows) { Situation s = new Situation(); b.Id = int.Parse(dr["id"].ToString()); b.Bw = dr["bw"].ToString(); b.Pinyin = dr["pinyin"].ToString(); b.Qianming = dr["qianming"].ToString(); } return(b); } catch (Exception) { //Do any logging operation here if necessary return null; } }
public List <Baowen> getListBaowen(int number) { try { var sql = "select * from baowen order by random() limit @number;"; var cmdparams = new List <SQLiteParameter>() { new SQLiteParameter("number", number) }; DataTable dt = sh.Select(sql, cmdparams); List <Baowen> listB = new List <Baowen>(); foreach (DataRow dr in dt.Rows) { Situation s = new Situation(); Baowen b = new Baowen(); b.Id = int.Parse(dr["id"].ToString()); string tempbw = dr["bw"].ToString(); b.Bw = tempbw.Replace(" ", ""); b.Pinyin = dr["pinyin"].ToString(); b.Qianming = dr["qianming"].ToString(); listB.Add(b); } return(listB); } catch (Exception) { //Do any logging operation here if necessary return null; } }
public void UpdateBaowen(Baowen baowen) { try { var sql = "update baowen set bw=@bw,pinyin=@pinyin,qianming=@qianming where id=@id;"; var cmdparams = new List <SQLiteParameter>() { new SQLiteParameter("bw", baowen.Bw), new SQLiteParameter("pinyin", baowen.Pinyin), new SQLiteParameter("qianming", baowen.Qianming), new SQLiteParameter("id", baowen.Id) }; sh.Execute(sql, cmdparams); } catch (Exception) { //Do any logging operation here if necessary } }
public int InsertBaowen(Baowen baowen) { try { var sql = "insert into baowen(bw,pinyin,qianming) values (@bw,@pinyin,@qianming);"; var cmdparams = new List <SQLiteParameter>() { new SQLiteParameter("bw", baowen.Bw), new SQLiteParameter("pinyin", baowen.Pinyin), new SQLiteParameter("qianming", baowen.Qianming), new SQLiteParameter("id", baowen.Id) }; sh.Execute(sql, cmdparams); int re = Convert.ToInt32(sh.ExecuteScalar("select last_insert_rowid();")); return(re); } catch (Exception) { //Do any logging operation here if necessary return(-1); } }