掌握TreeView用法
DAL层代码:
1 using System.Collections.Generic;
2 using System.Data;
3 using DataTreeModel;
4 using System.Data.SqlClient;
5 using System.Windows.Forms;
6
7 namespace DataTreeDAL
8 {
9 class TreesNodeDAL
10 {
11 //根据Parentid返回表中所有的的实体对象
12 public IEnumerable<ItemsNode> GetEveryOneByParent(int id)
13 {
14 DataTable dt=sqlHelper.GetDatatable("select * from ItemsNode where parentId =@id",
15 new SqlParameter("id",id));
16 List<ItemsNode> list = new List<ItemsNode>();
17 foreach (DataRow row in dt.Rows)
18 {
19 list.Add(CreateItemsNose(row));//添加对象
20 }
21 return list;
22 }
23 //更新表中的记录
24 public int UpdateRecord(ItemsNode item)
25 {
26 return sqlHelper.ExecuteNonQuery("update ItemsNode set name=@name,content=@content where id=@id", new SqlParameter("name", item.name), new SqlParameter("content", item.content),new
27 SqlParameter("id",item.Id));
28 }
29
30 public int InsertRecord(ItemsNode item)
31 {
32 return sqlHelper.ExecuteNonQuery("Insert into ItemsNode (name,content,parentId) values(@name,@content,@parentId)", new SqlParameter("name", item.name), new SqlParameter("content", item.content), new
33 SqlParameter("parentId", item.parentId));
34 }
相关新闻>>
- 发表评论
-
- 最新评论 更多>>