初识三层架构(4)
}
}
}
DAL
1 using System;
2 using 三层架构.Model;
3 using System.Data.SqlClient;
4 using System.Data;
5 using System.Collections.Generic;
6
7 namespace 三层架构.DAL
8 {
9 class PersonDAL
10 {
11 //增加字段
12 public static int AddNew(Person model)//返回新添加字段的主键
13 {
14 object obj= SQLHelper.ExecuteScalar("insert into T_person(Age,Name) output inserted.id values(@Age,@Name)",new SqlParameter("Age",model.Age),new SqlParameter("Name",model.Name));
15 return Convert.ToInt32(obj);
16 }
17 //删除操作www.2cto.com
18 public static int Delete(int id)
19 {
20 return SQLHelper.ExecuteNonQuery("delete from T_person where id=@id", new SqlParameter("id", id));
21 }
22 //更新数据
23 public static int UpDate(Person model)
24 {
25 return SQLHelper.ExecuteNonQuery("update T_Person set age=@age,name=@name where id=@id",new SqlParameter("age",model.Age), new SqlParameter("name",model.Name),new SqlParameter("id",model.Id));
26 }
27 //查询数据
28 public static Person GetPerson(int id)
29 {
30 DataTable dt=SQLHelper.ExecuteDataTable("select * from T_Person where id=@id",new SqlParameter("id",id));
31 if (dt.Rows.Count <= 0)
32 {
33 return null;
34 }
35 else if (dt.Rows.Count ==1)
36 {
相关新闻>>
- 发表评论
-
- 最新评论 更多>>