📄 sqlstring.cs
字号:
/* ***************************************
* 文件名称:SQLString.cs
* 功能:构造SQL语句功能包含两种方法:
* 1.能将字符串加上SQL常用的单引号
* 2.构造SQL条件语句
* 创建时期:
****************************************8 */
using System;
using System.Collections;
namespace TQMS.DataAccessHelper
{
/// <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().ToString()=="System.String" || item.Value.GetType().ToString()=="System.DateTime")
{
if (item.Key.ToString() == "TQ_QuestionContent")
{
Where += "[" + item.Key.ToString() + "] "
+ "Like"
+ SqlStringConstructor.GetQuotedString("%"+item.Value.ToString()+"%");
}
else
{
Where += "[" + item.Key.ToString() + "] "
+ "= "
+ 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 + -