Asp.net源码专业站
首页->投票调查->苹果投票系统源码及毕业论文>>App-Code/DB.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:苹果投票系统源码及毕业论文
当前文件:文件类型 AppleVote/App_Code/DB.cs[2K,2009-6-12 11:31:41]打开代码结构图
普通视图
		            
1 2using System; 3using System.Data; 4using System.Configuration; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13/// <summary> 14/// data 的摘要说明 15/// </summary> 16public class DB 17{ 18 SqlConnection con = null;//定义一个类属性,类型为SQL连接 19 SqlCommand cmd = new SqlCommand();//针对数据库操作的命令对象 20 21 public DB() 22 { 23 con = new SqlConnection("Data Source=.;Initial Catalog=vote;uid=sa;pwd=sa;"); 24 } 25 public SqlConnection getcon() 26 { 27 if (con.State == ConnectionState.Closed) 28 con.Open(); 29 return con; 30 31 32 } 33 public SqlConnection clear() 34 { 35 if (con.State == ConnectionState.Open) 36 con.Close(); 37 return con; 38 39 40 41 } 42 public void NonQueryexecute(string strsql) 43 { 44 45 cmd.Connection = getcon(); 46 cmd.CommandText = strsql; 47 cmd.ExecuteNonQuery(); 48 clear(); 49 50 51 } 52 //5 1 a s p x.com 53 54 public string executeGetReturn(string strsql)//strsql是传入SQL命令语句 55 { 56 //getcon(); 57 cmd.Connection = getcon(); 58 cmd.CommandText = strsql; 59 string result = cmd.ExecuteScalar().ToString(); 60 clear(); 61 return result; 62 63 } 64 public SqlDataReader getsdr(string strsql) 65 { 66 cmd.Connection = getcon(); 67 cmd.CommandText = strsql; 68 SqlDataReader sdr = cmd.ExecuteReader(); 69 return sdr; 70 71 72 } 73 public bool trantion(string[] sql) 74 { 75 bool flag = false; 76 con = getcon(); 77 cmd.Connection = con; 78 SqlTransaction mytransaction; 79 mytransaction = con.BeginTransaction(); 80 try 81 { 82 for (int i = 0; i < sql.Length; i++) 83 { 84 cmd.Transaction = mytransaction; 85 cmd.CommandText = sql[i]; 86 cmd.ExecuteNonQuery(); 87 88 } 89 mytransaction.Commit(); 90 flag = true; 91 92 } 93 catch 94 { 95 mytransaction.Rollback(); 96 flag = false; 97 98 } 99 finally 100 { 101 clear(); 102 103 } 104 105 return flag; 106 107 108 } 109} 110
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:苹果投票系统源码及毕业论文
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146