您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->唐唐企业管理网站源码>>App-Code/SqlHelper.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:唐唐企业管理网站源码
当前文件:文件类型 TangCompany/App_Code/SqlHelper.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Web; 5using System.Web.Security; 6using System.Web.UI; 7using System.Web.UI.WebControls; 8using System.Web.UI.WebControls.WebParts; 9using System.Web.UI.HtmlControls; 10using System.Data.SqlClient; 11//该源码首发自www.51aspx.com(51aspx.com) 12 13/// <summary> 14/// SqlHelper 的摘要说明 15/// </summary> 16public class SqlHelper 17{ 18 private static readonly string strConn = ConfigurationManager.ConnectionStrings["TangCompanyConn"].ConnectionString; 19 private static readonly string strName = ConfigurationManager.AppSettings["userName"].ToString(); 20 private static readonly string strPass = ConfigurationManager.AppSettings["userPass"].ToString(); 21 public SqlHelper() 22 { 23 // 24 // TODO: 在此处添加构造函数逻辑 25 // 26 } 27 public static SqlDataReader ExcuteRead(string nText, CommandType nType, SqlParameter[] paras) { 28 29 SqlConnection conn = new SqlConnection(strConn); 30 SqlCommand cmd = new SqlCommand(); 31 try 32 { 33 PrepareCommand(conn, cmd, null, nType, nText, paras); 34 SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); 35 cmd.Parameters.Clear(); 36 return dr; 37 38 } 39 catch(SqlException ex){ 40 41 throw new Exception(ex.Message, ex); 42 43 } 44 45 } 46 public static int ExcuteNonQurey(string nText, CommandType nType, SqlParameter[] paras) { 47 48 SqlCommand cmd = new SqlCommand(); 49 using (SqlConnection conn = new SqlConnection(strConn)) { 50 51 PrepareCommand(conn, cmd, null, nType, nText, paras); 52 int rows = cmd.ExecuteNonQuery(); 53 cmd.Parameters.Clear(); 54 return rows; 55 56 } 57 58 } 59 public static object ExcuteSclare(string nText, CommandType nType, SqlParameter[] paras) { 60 61 SqlCommand cmd = new SqlCommand(); 62 using (SqlConnection conn = new SqlConnection(strConn)) { 63 64 PrepareCommand(conn, cmd, null, nType, nText, paras); 65 object obj = cmd.ExecuteScalar(); 66 cmd.Parameters.Clear(); 67 return obj; 68 } 69 70 } 71 public static DataSet ExcuteReadApdater(string nText, CommandType nType, SqlParameter[] paras) { 72 73 SqlConnection con = new SqlConnection(strConn); 74 SqlCommand cmd = new SqlCommand(); 75 DataSet ds = new DataSet(); 76 try 77 { 78 PrepareCommand(con, cmd, null, nType, nText, paras); 79 SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); 80 sqlAdapter.Fill(ds); 81 cmd.Parameters.Clear(); 82 return ds; 83 84 } 85 catch (SqlException ex) { 86 87 throw new Exception(ex.Message, ex); 88 89 } 90 } 91 public static void PrepareCommand(SqlConnection con, SqlCommand cmd, SqlTransaction trans, CommandType nType, string nText, SqlParameter[] paras) { 92 93 if (con.State != ConnectionState.Open) 94 con.Open(); 95 cmd.Connection = con; 96 cmd.CommandText = nText; 97 if (trans != null) { 98 99 cmd.Transaction = trans; 100 } 101 cmd.CommandType = nType; 102 if (paras != null) { 103 104 foreach (SqlParameter para in paras) { 105 106 cmd.Parameters.Add(para); 107 } 108 109 } 110 } 111 112} 113
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:唐唐企业管理网站源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号