您目前尚未登陆,请选择【登陆】或【注册
首页->博客论坛->博客源代码(课程设计,3层架构)>>App-Code/LiuyanOperation.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:博客源代码(课程设计,3层架构)
当前文件:文件类型 MVCBlog/App_Code/LiuyanOperation.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Data.SqlClient; 5using System.Collections.Generic; 6/// <summary> 7/// LiuyanOperation 的摘要说明 8/// </summary> 9public class LiuyanOperation 10{ 11 private SqlConnection con = null; 12 private SqlCommand cmd = null; 13 14 public LiuyanOperation() 15 { 16 // 17 // TODO: 在此处添加构造函数逻辑 18 // 19 this.con = ConDB.getConnection();//在构造函数中连接数据库! 20 } 21 public bool insert_ly(liuyan at)//插入留言函数! 22 { 23 24 con.Open(); 25 cmd = new SqlCommand("insert into liuyantable(CNAME,LIUYAN_CONTENT) values(@author,@content)", con); 26 cmd.Parameters.Add(new SqlParameter("@content", at.content)); 27 cmd.Parameters.Add(new SqlParameter("@author", at.author)); 28 if (cmd.ExecuteNonQuery() > 0) 29 { 30 con.Close(); 31 return true; 32 } 33 else 34 { 35 con.Close(); 36 return false; 37 } 38 } 39 public bool update(liuyan ac) 40 { 41 con.Open(); 42 cmd = new SqlCommand("update liuyantable set liuyan_huifu=@huifu where id=@aid", con); 43 cmd.Parameters.Add(new SqlParameter("@aid", ac.id)); 44 cmd.Parameters.Add(new SqlParameter("@huifu", ac.huifu)); 45 // cmd.Parameters.Add(new SqlParameter("@huifu_time", ac.huifutime)); 46 if (cmd.ExecuteNonQuery() > 0) 47 { 48 con.Close(); 49 return true; 50 } 51 else 52 { 53 con.Close(); 54 return false; 55 } 56 } 57 public List<liuyan> viewAll() 58 { 59 List<liuyan> list = new List<liuyan>(); 60 con.Open(); 61 cmd = new SqlCommand("select * from liuyantable order by liuyan_time desc", con); 62 SqlDataReader sdr = cmd.ExecuteReader(); 63 liuyan ac; 64 while (sdr.Read()) 65 { 66 ac = new liuyan(); 67 ac.id = sdr["ID"].ToString(); 68 69 ac.author = sdr["CNAME"].ToString(); 70 71 ac.content = sdr["liuyan_content"].ToString(); 72 73 ac.huifu = sdr["LIUYAN_HUIFU"].ToString(); 74 75 ac.huifutime = Convert.ToDateTime(sdr["LIUYAN_HUIFU_TIME"]); 76 ac.time = Convert.ToDateTime(sdr["LIUYAN_TIME"]); 77 78 list.Add(ac); 79 } 80 sdr.Close(); 81 con.Close(); 82 return list; 83 } 84 public liuyan getByAid(string aid)//获取文章内容 85 { 86 con.Open(); 87 cmd = new SqlCommand("select * from liuyantable where id='" + aid + "'", con); 88 SqlDataReader dr = cmd.ExecuteReader(); 89 liuyan ac = null; 90 while (dr.Read()) 91 { 92 ac = new liuyan(dr); 93 } 94 con.Close(); 95 return ac; 96 } 97 public bool delete(string aid) 98 { 99 con.Open(); 100 cmd = new SqlCommand("delete from liuyantable where id='" + aid + "'", con); 101 if (cmd.ExecuteNonQuery() > 0) 102 { 103 con.Close(); 104 return true; 105 } 106 else 107 { 108 con.Close(); 109 return false; 110 } 111 112 } 113 114} 115
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:博客源代码(课程设计,3层架构)
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号