public bool updateToTable(ref string strToUpd,ref string strTable)
        {
            try
            {
                strToUpd = strToUpd.Replace("'", "''");
                string strUpd = "update " + strTable + " set bSiteDowned= '" + strToUpd + "' where bSiteToDown= '" + strToUpd + "'";
                MessageBox.Show(strUpd);
                OleDbCommand oleDbCommand = new OleDbCommand(strToUpd, Program.oleDbConn);
                oleDbCommand.ExecuteNonQuery();
                            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message);            
            }
            return true;
            
        }下面是数据库中测试的语句: 
update blogDownState set bSiteDowned='http://12december2008.blogspot.com/' where bSiteToDown='http://12december2008.blogspot.com/'在上面的c#代码中,运行时提示说'http'附近有语法错误我没有看出来啊

解决方案 »

  1.   

    不要直接这样写,写参数。
    String strSQL="update @table set bSiteDowned=@bSiteDowned where bSiteToDown=bSiteToDown";
    OleDbParameter[]param={
     new OleDbParamter("@table","blogDownState"),
     new OleDbParamter("@table","blogDownState"),///这里分别改成数据库的字段,
     new OleDbParamter("@table","blogDownState"),
    };
      

  2.   

    加上
    strToUpd = strToUpd.Replace("'", "''");
    strToUpd = strToUpd.Replace("/", "//");
                  
      

  3.   

    谢谢各位,我试试,但是下面这个插入函数就运行的很好,是什么原因呢?
            public bool insertToTable(ref string strToIns,ref string strTable )
            {
                strToIns=strToIns.Replace("'", "''");
                string sqlIns = "insert into "+strTable+" (bSiteToDown) values ('"+strToIns+"')";
                OleDbCommand oleDbCommand = new OleDbCommand(sqlIns, Program.oleDbConn);
                oleDbCommand.ExecuteNonQuery();
                return true;
            }
      

  4.   

    strToUpd = strToUpd.Replace("'", "''");
                    string strUpd = "update " + strTable + " set bSiteDowned= '" + strToUpd + "' where bSiteToDown= '" + strToUpd + "'";
                    MessageBox.Show(strUpd);
                    OleDbCommand oleDbCommand = new OleDbCommand(strToUpd, Program.oleDbConn);
                    oleDbCommand.ExecuteNonQuery();
    你在new OleDbCommand(),括号里的变量写错了
      

  5.   

    是转义字符的问题吧!
    oleDbCommand.Parameters.add("@xx",类型,大小);
    oledbCommand["@xx"].value="";
    行不?
      

  6.   

    lovelife_go一语中地.
    太过分了,怀疑自己弱智,这种错误都会犯!
    谢谢大家,结贴!
      

  7.   

    用HtmlEncode对'http://12december2008.blogspot.com/'做个编码试试看