日期:2014-05-18  浏览次数:22013 次

索引和长度必须引用该字符串内的位置。 参数名: length
大家帮忙看看错哪了!
C# code

 string FileContent = Session["data"].ToString();
        string Name = name.Text.Trim().ToString();
        string zuozhe = author.Text.Trim().ToString();
        string jieshao = jianjie.Text.Trim().ToString();
        string str = "insert into achievements(project_name,deveolpers,explanation,url) values('" + Name + "','" + zuozhe + "'','" + jieshao + "','" + FileContent + "')";
        if (gwolf_bll.action1(str))
        {
            Response.Write("<script>alert('数据插入成功!')</script>");
        }
        else
        {
            Response.Write("<script>alert('数据插入失败!')</script>");
        }


  public static bool action1(string SQLstring)
        {
            return gwolf_dal.zx(SQLstring);
        }

 public static bool zx(string SQLstring)
        {
            ConOpen();
            Sqlcmd = new MySqlCommand(SQLstring, Sqlcon);
            try
            {
                int count = Convert.ToInt32(Sqlcmd.ExecuteNonQuery());
                if (count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                ConClose();
            }
        }





------解决方案--------------------
string str = "insert into achievements(project_name,deveolpers,explanation,url) values('" + Name + "','" + zuozhe + "'','" + jieshao + "','" + FileContent + "')";
红色部分多了一个单引号,去掉,建议用参数化查询
------解决方案--------------------
http://blog.csdn.net/pksniq/article/details/6870388

http://oswica.blog.51cto.com/756561/467580