先留個言, 有空來補內容.
VB
Public Module SqlStringExtention
<Extension()>
Function SQLStr(ByVal Original As String) As String
Return Original.Replace("'", "''")
End Function
<Extension()>
Function SQLTrim(ByVal Original As String) As String
Return Original.Trim.Replace("'", "''")
End Function
End Module
C#
//Extension methods must be defined in a static class
public static class StringExtension
{
/// <summary>
/// 把 ' 取代成 ''
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string sqlStr(this string value)
{
return value.Replace("'", "''");
}
/// <summary>
/// 假設欄位名稱中不會有 [ 或 ] 的符號
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string sqlField(this string value)
{
return "[" + value.Replace("[", "").Replace("]", "") + "]";
}
}