您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->博客源代码(课程设计,3层架构)>>App-Code/CommentOperate.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:博客源代码(课程设计,3层架构)
当前文件:文件类型 MVCBlog/App_Code/CommentOperate.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Data.SqlClient; 5using System.Collections.Generic; 6 7 8 9 10public 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
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:博客源代码(课程设计,3层架构)
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号