?? sqlstring.cs
字號:
using System;
using System.Collections;
namespace eBookShop.DAL
{
/// <summary>
/// SQLString 的摘要說明。
/// </summary>
public class SqlStringConstructor
{
/// <summary>
/// 公有靜態方法,將文本轉換成適合在Sql語句里使用的字符串。
/// </summary>
/// <returns>轉換后文本</returns>
public static String GetQuotedString(String pStr)
{
return ("'" + pStr.Replace("'","''") + "'");
}
/// <summary>
/// 根據條件哈希表,構造SQL語句中的條件子句
/// </summary>
/// <param name="conditionHash">條件哈希表</param>
/// <returns>條件子句</returns>
public static String GetConditionClause(Hashtable queryItems)
{
int Count = 0;
String Where = "";
//根據哈希表,循環生成條件子句
foreach(DictionaryEntry item in queryItems)
{
if (Count == 0)
Where = " Where ";
else
Where += " And ";
//根據查詢列的數據類型,決定是否加單引號
if(item.Value.GetType().Name=="String" || item.Value.GetType().Name=="DateTime")
{
Where += "[" + item.Key.ToString() + "]"
+ "Like "
+ SqlStringConstructor.GetQuotedString("%"
+ item.Value.ToString()
+ "%");
}
else
{
Where += "[" + item.Key.ToString() + "]" + "= " + item.Value.ToString();
}
Count ++;
}
return Where;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -