插入代码如下:          string type = Request.QueryString["type"];
            string Mysql, UserName, Email, Phone, Address, Title, Content;
            UserName=Check.checkWebAsp(Request.Form["user"]);
            Email=Check.checkWebAsp(Request.Form["email"]);
            Phone=Check.checkWebAsp(Request.Form["tel"]);
            Address=Check.checkWebAsp(Request.Form["address"]);
            Title=Check.checkWebAsp(Request.Form["title"]);
            Content=Check.checkWebAsp(Request.Form["question"]);
          Content=  Content.Replace("\r\n", "<br/>");
          Content = Content.Replace(" ", "&nbsp;");
            Mysql = "Insert Into mail (username,type,time,mail,topic,";
        if (Phone.Length>0 )
            Mysql=Mysql+"phone,";            if (Address.Length>0 )
        Mysql=Mysql+"address,";        if (Content.Length>0)
        Mysql=Mysql+"text,";        Mysql=Mysql+"reflag) Values ('"+UserName+"','"+type+"','"+DateTime.Now.ToString()+"','"+Email+"','"+Title+"',";
        if (Phone.Length>0 )
         Mysql=Mysql+"'"+Phone.Trim()+"',";        if (Address.Length>0)
        Mysql=Mysql+"'"+Address.Trim()+"',";
        if (Content.Length>0)
        Mysql=Mysql+"'"+Convert.ToString( Content).Trim()+"',";        Mysql = Mysql + "0)";
        InsertTab(Mysql);
        }text的字段是ntext,但是只能插入十来个字,其余的被截断了,为什么?

解决方案 »

  1.   

    不通过代码插入,直接写sql插入数据库看一下会不会截断。不会截断的话,说明是代码问题,检查一下代码。
      

  2.   

    是指直接在sql用插入吗?
      

  3.   

    用参数方法给ntext赋值啊,不要用拼字符串方式。
      

  4.   

    直接用sql可以插入。应该是程序有问题,可是。。是什么问题呢?
      

  5.   

    差不多就这样string ConStr = DataAccessLibrary.WebConfig.ConnectionString;
                SqlConnection conn = new SqlConnection(ConStr);
                string strSql = "insert into Hospital_Employees(EmpNum,EmpTypeNum,DeptNum,EmpName,EmpTelephone,EmpFingerTmp,EmpPassword,EmpLevel,ROLEID) values(@EmpNum,@EmpTypeNum,@DeptNum,@EmpName,@EmpTelephone,@EmpFingerTmp,@EmpPassword,@EmpLevel,@ROLEID)";
                SqlCommand cmd = new SqlCommand(strSql, conn);
                cmd.Parameters.Add("@EmpNum", SqlDbType.VarChar);
                cmd.Parameters["@EmpNum"].Value = empnum;            cmd.Parameters.Add("@EmpTypeNum", SqlDbType.SmallInt);
                cmd.Parameters["@EmpTypeNum"].Value = emptypenum;            cmd.Parameters.Add("@DeptNum", SqlDbType.Int);
                cmd.Parameters["@DeptNum"].Value = deptnum;            cmd.Parameters.Add("@EmpName", SqlDbType.VarChar);
                cmd.Parameters["@EmpName"].Value = empname;            cmd.Parameters.Add("@EmpTelephone", SqlDbType.VarChar);
                cmd.Parameters["@EmpTelephone"].Value = empphone;            cmd.Parameters.Add("@EmpFingerTmp", SqlDbType.Binary);
                cmd.Parameters["@EmpFingerTmp"].Value = sTemp;            cmd.Parameters.Add("@EmpPassword", SqlDbType.VarChar);
                cmd.Parameters["@EmpPassword"].Value = "";            cmd.Parameters.Add("@EmpLevel", SqlDbType.Int);
                cmd.Parameters["@EmpLevel"].Value = 1;            cmd.Parameters.Add("@ROLEID", SqlDbType.Int);
                cmd.Parameters["@ROLEID"].Value = roleid;
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                //设置数据库的sql语句
                string sql = string.Format("select EmpNum AS 员工编号,EmpTypeNum AS 员工类型编号,DeptNum AS 部门编号,EmpName AS 姓名,EmpTelephone AS 联系方式,ROLEID AS 角色编号 FROM Hospital_Employees");
                DataTable dt = BLL.RunSqlDataTable(sql);
      

  6.   

    InsertTab(Mysql);
    断点调试到这一句 把mysql里面的命令拷贝出来在数据库里运行下看看错误出在哪里?