Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新条目时出错。有关详细信息,请参见内部异常。保存更改问题_C#_Sql Server 2008_Visual Studio 2010 - Fatal编程技术网

C# 更新条目时出错。有关详细信息,请参见内部异常。保存更改问题

C# 更新条目时出错。有关详细信息,请参见内部异常。保存更改问题,c#,sql-server-2008,visual-studio-2010,C#,Sql Server 2008,Visual Studio 2010,这是我的班级代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Student_InfoFORM { public partial class tblStudentform { public static void createStudentform(string idno, string fname, string

这是我的班级代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Student_InfoFORM
{
    public partial class tblStudentform
    {
        public static void createStudentform(string idno, string fname, string mname, string lname, string add, string email)
        {
            Student_InfoFORM.studentFormEntities container = new Student_InfoFORM.studentFormEntities();

            tblStudentform std = new tblStudentform
            {
                stud_id = idno,
                firstname = fname,
                midname = mname,
                lastname = lname,
                address = add,
                emailadd = email
            };

            container.tblStudentforms.AddObject(std);
            container.SaveChanges();
        }
    }
}
这是来自
SaveChanges()
调用的消息:

更新条目时出错。有关详细信息,请参见内部异常

这是我每次保存在应用程序中输入的数据时的内部异常:

System.Data.UpdateException未由用户代码处理
HResult=-2146233087
消息=更新条目时出错。有关详细信息,请参见内部异常。
Source=System.Data.Entity

StackTrace:
在System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器)中
位于System.Data.EntityClient.EntityAdapter.Update(EntityStateManager entityCache)
位于System.Data.Objects.ObjectContext.SaveChanges(SaveOptions选项)
位于System.Data.Objects.ObjectContext.SaveChanges()
在C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student\InfoFORM\Student\InfoFORM\tblStudentform\tblStudentform.cs中的Student\u InfoFORM(字符串idno、字符串fname、字符串mname、字符串lname、字符串add、字符串电子邮件)中 在Student_InfoFORM._Default.Button1_单击C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student_InfoFORM\Student_InfoFORM\Default.aspx.cs中的(对象发送者,事件参数e):第19行
在System.Web.UI.WebControls.Button.OnClick(EventArgs e)
在System.Web.UI.WebControl.Button.RaisePostBackEvent(String eventArgument)
位于System.Web.UI.WebControl.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
位于System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)的System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)

InnerException:System.Data.SqlClient.SqlException
HResult=-2146232060
Message=字符串或二进制数据将被截断。该语句已终止。
Source=.Net SqlClient数据提供程序
错误代码=-2146232060
类别=16行编号=1行编号=8152
Procedure=”“Server=\SQLEXPRESSState=14

StackTrace:
System.Data.SqlClient.SqlConnection.OneError(SqlException异常,布尔断开连接,Action
1 wrapCloseInAction)System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常,布尔断开连接,Action
1 wrapCloseInAction)System.Data.SqlClient.TdsParser.ThroweException和WarningSystem.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject StateObjection,Boolean&dataReady)上的(SqlDataReader ds、RunBehavior RunBehavior、String ResetOptions String、Boolean isInternal、Boolean ForDescriptionParameterEncryption、Boolean shouldCacheForAlwaysEncrypted)位于System.Data.SqlClient.SqlCommand.RunExecuteReaderDS(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、Boolean async、Int32超时、任务和任务、Boolean asyncWrite、Boolean inRetry、SqlDataReader ds、Boolean describeParameterEncryptionRequest)位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法、TaskCompletionSource
1 completion、Int32超时、任务和任务、Boolean和usedCache、Boolean asyncWrite、Boolean inRetry)位于System.Data.SqlClient.SqlCommand.InternalExecuteInQuery(System.Data.SqlClient.SqlCommand.ExecuteOnQuery()的System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute)中的(TaskCompletionSource
1完成、字符串方法名、布尔sendToPipe、Int32超时、布尔和usedCache、布尔异步写入、布尔inRetry)(位于System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter adapter)的UpdateTranslator translator、EntityConnection连接、Dictionary
2个IdentifierValue、List
1个GeneratedValue)内部异常:


该错误意味着您传递的类型或数据对于当前列来说太大。我建议在字符串可用时使用nvarchar。如果您需要更改列大小,可以使用

ALTER TABLE TableName
ALTER COLUMN ColumnName TypeName(Size)

当您的字段大小小于您尝试插入的值时,将显示截断的字符串或二进制数据。数据库中的一个字符串大小小于您要传递的值是。当它停止加载时,浏览器中也会显示该值。如何修复它?检查数据库中的哪个字段大小较小。某些varchar(100)也许可以增加或减少代码的输入谢谢!varchar确实可以工作,不像我之前放的字符。谢谢!这是更好的解决方案。