向ACCESS库中保存html的时候如果有'号就会出现以下错误:语法错误 (操作符丢失) 在查询表达式 ''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>一起去看书_177ks_书籍列表页</title> <title>一起去看书____</title> <met' 中。
解决方案 »
- 调试和运行DEBUG有什么区别?
- SharpZipLib 解密
- 如何限制密码框的copy机能?
- 怎么用 xml 写一个简单的软件自动更新配置文件出来(愚翁好久不见了,进来看看)
- 关于Infragistics WinGrid控件的问题
- 在 WinForm 中. 怎么选中 DataGrid 控件中. 某一单元格
- 与dll有关的问题。请熟悉动态调用dll的进来帮忙解决。
- 提示未能访问cdo.message是什么原因呢,怎么解决?
- 怎么看自己的专家分啊,当然不是在专家排行榜里面
- 如何调用系统命令,如PONG,NET SEND 并得到结果
- 如何添加System.Drawing.Point类型的资源?
- 那个大侠能提供一些搜索引擎这方面的代码一起来讨论指点~!谢谢~
比如 ADODB.RECORDSET.OPEN 以后再UPDATE你必定要用 SQL 来保存的话请格式化字串,比如update table set fieldname =' ''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> '看见第一个单引号了么?要重复两遍,按你编写代码的环境不同,可能其中的双引号也全部要重复两遍 ,第一个引号是作为转义字符用的
/// <summary>
/// 转换非法字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns> public static string strEncode(string str)
{
if(str!=null)
{
System.Text.StringBuilder newstr=new System.Text.StringBuilder();
string xChar="";
int l=str.Length;
for(int i=0;i<l;i++)
{
xChar=str.Substring(i,1);
switch(xChar)
{
case("\'"):
newstr.Append("‘");
break;
case("\""):
newstr.Append("“");
break;
case("("):
newstr.Append("(");
break;
case(")"):
newstr.Append(")");
break;
case(":"):
newstr.Append(":");
break;
case("<"):
newstr.Append("<");
break;
case(">"):
newstr.Append(">");
break;
default:
newstr.Append(xChar);
break;
}
}
return newstr.ToString();
}
else
return null;
} #endregion
#region 转换非法字符(文本框格式内容转换)
/// <summary>
/// 转换非法字符
/// </summary>
/// <param name="str"></param>
/// <param name="style">Text</param>
/// <returns></returns> public static string strEncode(string str,string style)
{
if(str!=null)
{ System.Text.StringBuilder newstr=new System.Text.StringBuilder();
string xChar="";
int l=str.Length;
if(style=="xml")
{
for(int i=0;i<l;i++)
{
xChar=str.Substring(i,1);
switch(xChar)
{
case("\'"):
newstr.Append("‘");
break;
case("\""):
newstr.Append("“");
break;
case("("):
newstr.Append("(");
break;
case(")"):
newstr.Append(")");
break;
// case(":"):
// newstr.Append(":");
// break;
case("<"):
newstr.Append("<");
break;
case(">"):
newstr.Append(">");
break;
/* case(" "):
newstr.Append(" ");
break;
case("\n"):
* newstr.Append("<br>");
break;
case("\r"):
newstr.Append("<br>");
break; */ default:
newstr.Append(xChar);
break;
}
}
}
else
{
for(int i=0;i<l;i++)
{
xChar=str.Substring(i,1);
switch(xChar)
{
case("\'"):
newstr.Append("‘");
break;
case("\""):
newstr.Append("“");
break;
case("("):
newstr.Append("(");
break;
case(")"):
newstr.Append(")");
break;
case(":"):
newstr.Append(":");
break;
case(" "):
newstr.Append(" ");
break;
case("<"):
newstr.Append("<");
break;
case(">"):
newstr.Append(">");
break;
case("\n"):
newstr.Append("<br>");
break;
case("\r"):
newstr.Append("<br>");
break; default:
newstr.Append(xChar);
break;
}
}
}
return newstr.ToString();
}
else
return null;
} #endregion #region 反向转换非法字符
/// <summary>
/// 反向转换非法字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns> public static string strUNEncode(string str)
{
str=str.Replace("“","\"");
str=str.Replace("‘","\'");
str=str.Replace(")",")");
str=str.Replace("(","(");
return str;
} #endregion
#region 反向转换非法字符(文本框内容转换)
/// <summary>
/// 反向转换非法字符
/// </summary>
/// <param name="str"></param>
/// <param name="style">text为文本框格式的</param>
/// <returns></returns> public static string strUNEncode(string str,string style)
{
str=str.Replace("“","\"");
str=str.Replace("‘","\'");
str=str.Replace(")",")");
str=str.Replace("(","(");
str=str.Replace(">",">");
str=str.Replace("<","<");
str=str.Replace(" "," ");
str=str.Replace("<br>","\n"); return str;
}
}
}