Web.Model.News news = new Web.BLL.News().GetModel("id=" + arr_id[i]);
            if (news != null)
            {
                news.TypeID = int.Parse(toTypeid);
                news.SendTime = DateTime.Now;
                news.EditTime = DateTime.Now;
                news.Title = news.Title.Replace("'", "''");
                news.TitleToIndex = news.Title.Replace("'", "''");
                news.WordKey = news.Title.Replace("'", "''");
                news.Content = news.Content.Replace("'", "''");
                if (isCut)
                {
                    new Web.BLL.News().Update(news);
                }
                else
                {
                    new Web.BLL.News().Add(news);
                }替换是什么意思????????????????

解决方案 »

  1.   

    在写数据库的时候, '在sql中表示字符串的开始于结束。为了把'放入字符串,需要用连续两个''。
    这个很像C#中用\"代替"一样。
      

  2.   

    防止sql注入,单引号在sql中是用来表示字符串的
      

  3.   

    把单引号替换成双引号
    Replace("1","2");  //把1替换为2
    --
    楼主应该多用百度,这种问题只要搜索 [replace() 用法],相信可以很快找到答案.
      

  4.   

    简单说就是为了防止sql注入。
      

  5.   

    你可以做一个实验比如在你的页面中放一个textbox然后你写个语句update table1 set 一个字段='"+textbox.Text+"' where id=1然后你在textbox中输入一个单引号试试..然后你再replace("'", "''"); 再试试.遇到问题多动手试一下!
      

  6.   

    楼上说的对啊..要自己多动手~~
    你把它用字符串输出看一下
    Response.Write(news.Content );
    再拿到 SQL 里运行一下,就什么都明白了
      

  7.   

    考虑下:string str1 = "name";
    string str2 = "Jame's"如果没有replace 
    可以很轻松的把 str1 插入到数据库。string sqlString = "insert into table1 ...'" + str1 + "'..." ;如果string 中有 ' 单引号   那就不会这么简单了。
    那样的话, 就会出现 错误, 不是你想得到的字符串。try try see.
      

  8.   

    简单的说就是防止Sql注入
    但是如果字段是数字型就不能简单的用Replace方式,而应该先判断是不是数字。
      

  9.   

    SQL需要这样写,才能准确的把字符串存进去