您目前尚未登陆,请选择【登陆】或【注册
首页->行政办公->多功能在线考试系统改进版源码>>App-Code/DataAccessHelper/SQLString.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:多功能在线考试系统改进版源码
当前文件:文件类型 OnLineExamUpdate/App_Code/DataAccessHelper/SQLString.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections; 3//51aspx.com 4namespace OnLineExam.DataAccessHelper 5{ 6 //对传递过来的字符串进行处理的类 7 public class SQLString 8 { 9 //公有静态方法,将SQL字符串里面的(')转换成('') 10 public static String GetSafeSqlString(String XStr) 11 { 12 return XStr.Replace("'","''"); 13 } 14 15 //公有静态方法,将SQL字符串里面的(')转换成(''),再在字符串的两边加上(') 16 public static String GetQuotedString(String XStr) 17 { 18 return ("'" + GetSafeSqlString(XStr) + "'"); 19 } 20 public static String GetConditionClause(Hashtable queryItems) 21 { 22 23 int Count = 0; 24 String Where = ""; 25 26 //根据哈希表,循环生成条件子句 27 foreach (DictionaryEntry item in queryItems) 28 { 29 if (Count == 0) 30 Where = " Where "; 31 else 32 Where += " And "; 33 34 //根据查询列的数据类型,决定是否加单引号 35 if (item.Value.GetType().ToString() == "System.String" || item.Value.GetType().ToString() == "System.DateTime") 36 { 37 Where += item.Key.ToString() 38 + " Like " 39 + SQLString.GetQuotedString("%" 40 + item.Value.ToString() 41 + "%"); 42 } 43 else 44 { 45 Where += item.Key.ToString() + "= " + item.Value.ToString(); 46 } 47 Count++; 48 } 49 return Where; 50 } 51 /// <summary> 52 /// 根据条件哈希表,构造SQL语句中的条件子句 53 /// </summary> 54 /// <param name="conditionHash">条件哈希表</param> 55 /// <param name="type">与还是或查询,取值={"AND","OR"}</param> 56 /// <returns>AND关系条件子句</returns> 57 public static String GetConditionClause(Hashtable queryItems, string type) 58 { 59 60 int Count = 0; 61 String Where = ""; 62 63 //根据哈希表,循环生成条件子句 64 foreach (DictionaryEntry item in queryItems) 65 { 66 if (Count == 0) 67 Where = " Where "; 68 else 69 Where += " " + type + " "; 70 71 //根据查询列的数据类型,决定是否加单引号 72 if (item.Value.GetType().ToString() == "System.String" || item.Value.GetType().ToString() == "System.DateTime") 73 { 74 Where += item.Key.ToString() 75 + " Like " 76 + SQLString.GetQuotedString("%" 77 + item.Value.ToString() 78 + "%"); 79 } 80 else 81 { 82 Where += item.Key.ToString() + "= " + item.Value.ToString(); 83 } 84 Count++; 85 } 86 return Where; 87 } 88 } 89} 90
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:多功能在线考试系统改进版源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号