//接收一个长度大于8000的字符串
string a=textBox1.Text;(textbox1输入一个字符数量超过8000字符串)
// 插入一张表里
sqlcommand cmd1= new sqlcommand("insert into table1(content) values(@content)",this.conn.dbconn);
cmd1.Parameters.Add("@content", a)运行时报错
赋予 类型 'varchar' 的大小(8050)超过了任意数据类型的最大允许值(8000)。必须声明变量 '@content'但我的content字段在sql server 里定义的是ntext型(ntext型的容量为最大2的30次方),而c#中的string型的储存长度也应该是大于8000呀,不知是怎么回事,请大虾们帮帮忙(语法大家不用研究,没有问题,我这里只是写个大概的意思)

解决方案 »

  1.   

    应在这句cmd1.Parameters.Add("@content", a)
    加上数据类型才行:
    SqlDbType.NText
      

  2.   

    例如:
    SqlParameter parameter = new SqlParameter("@Description");
    parameter.SqlDbType=SqlDbType.NText;
    parameter.IsNullable = true;
    parameter.Value = paramValue;cmd.Parameters.Add(parameter);
      

  3.   

    8000是varchar的长度
    cmd1.Parameters.Add("@content", a) 这样的写法不对的吧?
      

  4.   

    --引用
    例如:
    SqlParameter parameter = new SqlParameter("@Description");
    parameter.SqlDbType=SqlDbType.NText;
    parameter.IsNullable = true;
    parameter.Value = paramValue;cmd.Parameters.Add(parameter);
    有没有简便一些的写法呢
    比如说
    cmd1.Parameters.Add(sqlDbType.NText("@content"), a)行不?
      

  5.   

    SQL中好象一句SQL语句不能超过4000个字符的
      

  6.   

    我的参数比较多,所以就直接这样写了
    command1.Parameters.Add("@1", 1);
    command1.Parameters.Add("@2", 2);
    command1.Parameters.Add("@3", 3);
    command1.Parameters.Add("@4", 4);
    command1.Parameters.Add("@5", 5);
    ......
    能不能直接在add方法的时候加入数据类型,
      

  7.   

    SqlParameter param = command.Parameters.Add("@Description", SqlDbType.NVarChar, 16);
    param.Value = "Beverages";
      

  8.   

    将command1.Parameters.Add("@Content",a);改成 command1.Parameters.Add("@CategorySubPageTemplet",System.Data.SqlDbType.NText,500,a);大字符串保存是成功了
    但再次读取后还是修改前的值,这是怎么回事呀
      

  9.   

    command1.Parameters.Add"@CategorySubPageTemplet",System.Data.SqlDbType.NText,500,a);
    为什么要给NText类型的数据500个长度!!!???对于这个类型不设置长度的.
      

  10.   

    刚才写错了,
    SqlCommand command1 = new SqlCommand("update JF_Category set CategoryName=@CategoryName,FileExt=@FileExt,CategorySet=@CategorySet,CategoryIndexTemplet=@CategoryIndexTemplet,CategorySubPageTemplet=@CategorySubPageTemplet,NewsTemplet=@NewsTemplet,CategoryDir=@CategoryDir,CategoryDomain=@CategoryDomain,PageSize=@PageSize,CategoryNavigation=@CategoryNavigation,NewsNavigation=@NewsNavigation,AutoUpdate=@AutoUpdate where CategoryID=@CategoryID", this.conn.dbconn);
    command1.Parameters.Add("@CategoryName", this.g_CategoryName);
    command1.Parameters.Add("@FileExt", this.g_FileExt);
    command1.Parameters.Add("@CategorySet", this.CategorySet);
    command1.Parameters.Add("@CategoryIndexTemplet",this.g_CategoryIndexTemplet);
    command1.Parameters.Add("@CategorySubPageTemplet",SqlDbType.NText,16,this.g_CategorySubPageTemplet);
    command1.Parameters.Add("@NewsTemplet", this.g_NewsTemplet);
    command1.Parameters.Add("@CategoryDir", this.g_CategoryDir);
    command1.Parameters.Add("@CategoryDomain", this.g_CategoryDomain);
    command1.Parameters.Add("@PageSize", this.g_PageSize);
    command1.Parameters.Add("@CategoryNavigation", this.g_CategoryNavigation);
    command1.Parameters.Add("@NewsNavigation", this.g_NewsNavigation);
    command1.Parameters.Add("@AutoUpdate", this.g_AutoUpdate);
    command1.Parameters.Add("@CategoryID", this.CategoryID);
    这是整个的语句
    改了@CategorySubPageTemplet后,系统报错:
    被准备语句 '(@CategoryName nvarchar(100),@FileExt nvarchar(500),@CategorySet' 需要参数 @CategoryName,但未提供该参数。
    怎么回事呀