温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:我的小书坊源码(三层实现)
当前文件:
MyBookShop/App_Code/DataAccessHelper/SQLString.cs,打开代码结构图
MyBookShop/App_Code/DataAccessHelper/SQLString.cs,打开代码结构图1using System; 2
using System.Collections; 3
//该源码下载自www.51aspx.com(51aspx.com) 4
5
namespace MyBookShop.DataAccessHelper 6
{ 7
/// <summary> 8
/// SQLString 的摘要说明。 9
/// </summary> 10
public class SqlStringConstructor 11
{ 12
/// <summary> 13
/// 公有静态方法,将文本转换成适合在Sql语句里使用的字符串。 14
/// </summary> 15
/// <returns>转换后文本</returns> 16
public static String GetQuotedString(String pStr) 17
{ 18
return ("'" + pStr.Replace("'","''") + "'"); 19
} 20
21
/// <summary> 22
/// 根据条件哈希表,构造SQL语句中的条件子句 23
/// </summary> 24
/// <param name="conditionHash">条件哈希表</param> 25
/// <returns>条件子句</returns> 26
public static String GetConditionClause(Hashtable queryItems) 27
{ 28
29
int Count = 0; 30
String Where = ""; 31
32
//根据哈希表,循环生成条件子句 33
foreach(DictionaryEntry item in queryItems) 34
{ 35
if (Count == 0) 36
Where = " Where "; 37
else 38
Where += " And "; 39
40
//根据查询列的数据类型,决定是否加单引号 41
if(item.Value.GetType().ToString()=="System.String" || item.Value.GetType().ToString()=="System.DateTime") 42
{ 43
Where += "[" + item.Key.ToString() + "]" 44
+ "Like " 45
+ SqlStringConstructor.GetQuotedString("%" 46
+ item.Value.ToString() 47
+ "%"); 48
} 49
else 50
{ 51
Where += "[" + item.Key.ToString() + "]" + "= " + item.Value.ToString(); 52
} 53
Count ++; 54
} 55
return Where; 56
} 57
} 58
} 59





}