关于数据读取插入(C#,SQLite)
来源:互联网 发布:男士香水知乎 编辑:程序博客网 时间:2024/06/05 02:46
读取:
public List<CategoryInfo> GetAllData() { List<Model.CategoryInfo> list = new List<CategoryInfo>(); string sql = "select * from CategoryInfo order by CatId desc"; using (SQLiteDataReader reader=SQLiteHelper.ExecuteReader(sql)) { while (reader.Read()) { Model.CategoryInfo categoryInfo = new CategoryInfo(); categoryInfo.Catid = Convert.ToInt32(reader[0]); categoryInfo.Catname = reader[1].ToString(); categoryInfo.Catnum = reader[2].ToString(); categoryInfo.Remark = reader[3].ToString(); categoryInfo.Delflag = Convert.ToInt32(reader[4]); categoryInfo.Subtime = Convert.ToDateTime(reader[5]); categoryInfo.Subby = Convert.ToInt32(reader[6]); list.Add(categoryInfo); } } return list; }
插入数据
public int InsertData(Model.CategoryInfo categoryInfo) { List<string> listParaName = new List<string>(); List<SQLiteParameter> listPara = new List<SQLiteParameter>(); IniList(categoryInfo, listParaName, listPara); string sql = "insert into CategoryInfo({0}) values({1});"; sql = string.Format(sql, string.Join(",", listParaName), "@" + string.Join(",@", listParaName)); return SQLiteHelper.ExecuteNonQuery(sql, listPara.ToArray()); }
其中插入后sql如下:
insert into CategoryInfo(Catname,Catnum,Delflag,Remark,Subby,Subtime) values(@Catname,@Catnum,@Delflag,@Remark,@Subby,@Subtime);
初始化
private void IniList(CategoryInfo categoryInfo, List<string> listParaName, List<SQLiteParameter> listPara) { if (categoryInfo.Catid!=null) { listParaName.Add("Catid"); listPara.Add(new SQLiteParameter("@Catid", categoryInfo.Catid)); } if (categoryInfo.Catname != null) { listParaName.Add("Catname"); listPara.Add(new SQLiteParameter("@Catname", categoryInfo.Catname)); } if (categoryInfo.Catnum != null) { listParaName.Add("Catnum"); listPara.Add(new SQLiteParameter("@Catnum", categoryInfo.Catnum)); } if (categoryInfo.Delflag != null) { listParaName.Add("Delflag"); listPara.Add(new SQLiteParameter("@DelFlag", categoryInfo.Delflag)); } if (categoryInfo.Remark != null) { listParaName.Add("Remark"); listPara.Add(new SQLiteParameter("@Remark", categoryInfo.Remark)); } if (categoryInfo.Subby != null) { listParaName.Add("Subby"); listPara.Add(new SQLiteParameter("@Subby", categoryInfo.Subby)); } if (categoryInfo.Subtime != null) { listParaName.Add("Subtime"); listPara.Add(new SQLiteParameter("@Subtime", categoryInfo.Subtime)); } }
0 0
- 关于数据读取插入(C#,SQLite)
- 向sqlite数据库插入和读取图片数据 (for ios)
- 在Sqlite数据库插入和读取图片数据
- 在Sqlite数据库插入和读取图片数据
- iOS sqlite数据库插入和读取图片数据
- sqlite数据库插入和读取图片数据 (for ios)
- 关于Map数据插入读取的问题
- 基于sqlite的c语言数据读取(c为主)
- SQLite初识(四)数据库插入数据
- 关于sqlite的文本字段插入blob数据
- sqlite 数据插入失败
- SQLite数据插入异常
- python sqlite 读取数据
- sqlite学习笔记9:C语言中使用sqlite之插入数据
- Sqlite 插入数据慢解决方法
- 批量数据插入SQLite全记录
- sqlite循环批量插入数据
- Sqlite 防止插入重复数据
- 【标准】ISO9001:2015新版标准正式发布
- HDU 5131 Song Jiang's rank list 2014ICPC广州站现场赛
- java中sleep和wait的异同
- C++ 创建多级目录
- iOS textfield设置左边距
- 关于数据读取插入(C#,SQLite)
- vs2013类模板的修改
- 游戏性能优化的经验谈
- 加权平均法和移动加权法的例题
- Magento搜索不准确的解决办法
- C# winform treeview node添加右键菜单并选中节点
- usb摄像头的录像时注意事项
- Java学习笔记【内部类】
- java ThreadPool判断是否所有任务都完成的方法