更新条目时出错。有关详细信息,请参阅内部异常。保存修改问题
An error occurred while updating the entries. See the inner exception for details. Save changes problem
这是我的 class 代码:
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()
电话的消息:
An error occurred while updating the entries. See the inner exception for details.
这是每次我保存在我的应用程序中输入的数据时的内部异常:
System.Data.UpdateException was unhandled by user code
HResult=-2146233087
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at Student_InfoFORM.tblStudentform.createStudentform(String idno, String fname, String mname, String lname, String add, String email) in C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student_InfoFORM\Student_InfoFORM\tblStudentform.cs:line 24
at Student_InfoFORM._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student_InfoFORM\Student_InfoFORM\Default.aspx.cs:line 19
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=String or binary data would be truncated. The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16 LineNumber=1 Number=8152
Procedure=""Server=\SQLEXPRESSState=14
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List
1 generatedValues)at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)InnerException:
该错误意味着您传递了错误的类型或对于当前列来说太大的数据。我建议在字符串可用时使用 nvarchar。如果您需要更改列大小,可以使用
ALTER TABLE TableName
ALTER COLUMN ColumnName TypeName(Size)
这是我的 class 代码:
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()
电话的消息:
An error occurred while updating the entries. See the inner exception for details.
这是每次我保存在我的应用程序中输入的数据时的内部异常:
System.Data.UpdateException was unhandled by user code
HResult=-2146233087
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.EntityStackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at Student_InfoFORM.tblStudentform.createStudentform(String idno, String fname, String mname, String lname, String add, String email) in C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student_InfoFORM\Student_InfoFORM\tblStudentform.cs:line 24
at Student_InfoFORM._Default.Button1_Click(Object sender, EventArgs e) in C:\Users\admin2\Documents\Visual Studio 2010\Projects\Student_InfoFORM\Student_InfoFORM\Default.aspx.cs:line 19
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=String or binary data would be truncated. The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16 LineNumber=1 Number=8152
Procedure=""Server=\SQLEXPRESSState=14StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List
1 generatedValues)at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)InnerException:
该错误意味着您传递了错误的类型或对于当前列来说太大的数据。我建议在字符串可用时使用 nvarchar。如果您需要更改列大小,可以使用
ALTER TABLE TableName
ALTER COLUMN ColumnName TypeName(Size)