UPDATE tb
SET content = REPLACE(content, '要替换的数据', '替换成数据')
不过这个方法有只能用于一般的字符串数据如verChar,最大为8000个字符。 要是遇上ntext 、text 这个函数就不顶用了,其他方法有:
程序读取修改 -- 最笨的方法(但靠谱)
DataSet ds
=
new
DataSet();
ds = myDataBase.get_DataSet( " select id,content from tb " );
DataView dataview = new DataView();
dataview = ds.Tables[ 0 ].DefaultView;
for ( int i = 0 ; i < dataview.Count; i ++ )
{
try
{
string content = ds.Tables[ 0 ].Rows[i][ " content " ].ToString();
newscontent = newscontent.Replace( " 要替换的数据 " , " 替换后数据 " );
StringBuilder sqlText = new StringBuilder( @" UPDATE tb SET content = @QTY where id= " + Convert.ToInt32(ds.Tables[ 0 ].Rows[i][ " id " ].ToString()) + " " );
myDataBase.by_parameter(sqlText, newscontent); // 更新这条内容
}
catch (Exception ex)
{
div1.InnerHtml += ex.Message.ToString();
continue ;
}
}
ds = myDataBase.get_DataSet( " select id,content from tb " );
DataView dataview = new DataView();
dataview = ds.Tables[ 0 ].DefaultView;
for ( int i = 0 ; i < dataview.Count; i ++ )
{
try
{
string content = ds.Tables[ 0 ].Rows[i][ " content " ].ToString();
newscontent = newscontent.Replace( " 要替换的数据 " , " 替换后数据 " );
StringBuilder sqlText = new StringBuilder( @" UPDATE tb SET content = @QTY where id= " + Convert.ToInt32(ds.Tables[ 0 ].Rows[i][ " id " ].ToString()) + " " );
myDataBase.by_parameter(sqlText, newscontent); // 更新这条内容
}
catch (Exception ex)
{
div1.InnerHtml += ex.Message.ToString();
continue ;
}
}