温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:博客源代码(课程设计,3层架构)
当前文件:
MVCBlog/App_Code/CommentOperate.cs,打开代码结构图
MVCBlog/App_Code/CommentOperate.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Data.SqlClient; 5
using System.Collections.Generic; 6
7
8
9
10
public class CommentOperate 11
{ 12
private SqlConnection con = null; 13
private SqlCommand cmd = null; 14
public CommentOperate() 15
{ 16
this.con = ConDB.getConnection(); 17
} 18
19
public bool insert(Comment ct) 20
{ 21
con.Open(); 22
cmd = new SqlCommand("insert into gentietable(g_id,g_content,g_author) values(@gid,@comment,@author)", con); 23
cmd.Parameters.Add(new SqlParameter("@gid", ct.gid)); 24
cmd.Parameters.Add(new SqlParameter("@comment", ct.gcontent)); 25
cmd.Parameters.Add(new SqlParameter("@author", ct.gauthor)); 26
if (cmd.ExecuteNonQuery() > 0) 27
{ 28
con.Close(); 29
return true; 30
} 31
else 32
{ 33
con.Close(); 34
return false; 35
} 36
} 37
38
public List<Comment> viewAllbyAid(string aid) 39
{ 40
List<Comment> list = new List<Comment>(); 41
con.Open(); 42
cmd = new SqlCommand("select * from gentietable where g_id='" + aid+"'", con); 43
SqlDataReader sdr = cmd.ExecuteReader(); 44
Comment ac; 45
while (sdr.Read()) 46
{ 47
ac = new Comment(sdr); 48
list.Add(ac); 49
} 50
sdr.Close(); 51
con.Close(); 52
return list; 53
} 54
public bool delete(string aid) 55
{ 56
con.Open(); 57
cmd = new SqlCommand("delete from gentietable where id='" + aid + "'", con); 58
if (cmd.ExecuteNonQuery() >= 0) 59
{ 60
con.Close(); 61
return true; 62
} 63
else 64
{ 65
con.Close(); 66
return false; 67
} 68
} 69
public bool deletebyarticle(string aid) 70
{ 71
con.Open(); 72
cmd = new SqlCommand("delete from gentietable where g_id='" + aid + "'", con); 73
if (cmd.ExecuteNonQuery() >= 0) 74
{ 75
con.Close(); 76
return true; 77
} 78
else 79
{ 80
con.Close(); 81
return false; 82
} 83
} 84
} 85





}
}