您目前尚未登陆,请选择【登陆】或【注册
首页->行政办公->酒店管理系统(三层开发)源码>>DAO/SQLHelp.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:酒店管理系统(三层开发)源码
当前文件:文件类型 ThreeLayerHotel/DAO/SQLHelp.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Data; 6using System.Data.SqlClient; 7//该源码下载自www.51aspx.com(51aspx.com) 8 9namespace DAL 10{ 11 public class SQLHelp 12 { 13 private static string dbConn = "server=.\\Sql2005;database=Hotel;uid=sa;pwd=sa;"; 14 15 /// <summary> 16 /// 集合查询:在此完成所有的集合类型查询 17 /// </summary> 18 /// <param name="sqlQuery">查询语句</param> 19 /// <returns>结果集合</returns> 20 public static DataTable FillTable(string sqlQuery) 21 { 22 using (SqlConnection con = new SqlConnection(dbConn)) 23 { 24 //创建数据适配器,将查询语句及连接字符串两个参数传进数据适配器 25 SqlDataAdapter da = new SqlDataAdapter(sqlQuery, con); 26 //新建一个表格对象dt,用来获取查询的数据 27 DataTable dt = new DataTable(); 28 try 29 { 30 //填充表格 31 da.Fill(dt); 32 //如果查询无误,则返回查询出的数据 33 return dt; 34 } 35 catch 36 { 37 //执行查询出现错误,返回null值 38 return null; 39 } 40 finally 41 { 42 //主动销毁所用的资源 43 dt.Dispose(); 44 da.Dispose(); 45 } 46 } 47 } 48 49 50 51 52 53 /// <summary> 54 /// 返回受影响的行数:在此完成所有的增、删、改类型的操作 55 /// </summary> 56 /// <param name="sqlQuery">操作语句</param> 57 /// <returns>返回结果: 58 /// 1 执行SQL语句成功 59 /// -1 SQL语句执行错误 60 /// -2 数据库连接失败 61 /// </returns> 62 public static int ExecQuery(string sqlQuery) 63 { 64 using (SqlConnection con = new SqlConnection(dbConn)) 65 { 66 //建立sqlcommand对象,将sql语句及连接字符串放到sqlcommand的参数里 67 SqlCommand cmd = new SqlCommand(sqlQuery, con); 68 try 69 { 70 //打开连接 71 con.Open(); 72 try 73 { 74 //执行sql语句 75 cmd.ExecuteNonQuery(); 76 return 1; 77 } 78 catch 79 { 80 return -1; 81 } 82 } 83 catch 84 { 85 return -2; 86 } 87 finally 88 { 89 //主动销毁资源 90 cmd.Dispose(); 91 } 92 } 93 } 94 95 public static int UnusualExecQuery(string sqlQuery) 96 { 97 using (SqlConnection con = new SqlConnection(dbConn)) 98 { 99 //建立sqlcommand对象,将sql语句及连接字符串放到sqlcommand的参数里 100 SqlCommand cmd = new SqlCommand(sqlQuery, con); 101 try 102 { 103 //打开连接 104 con.Open(); 105 try 106 { 107 //执行sql语句 108 return cmd.ExecuteNonQuery(); 109 } 110 catch 111 { 112 return -1; 113 } 114 } 115 catch 116 { 117 return -2; 118 } 119 finally 120 { 121 //主动销毁资源 122 cmd.Dispose(); 123 } 124 } 125 } 126 } 127} 128
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:酒店管理系统(三层开发)源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号