2014-06-15 3 views
-1

내 프로젝트를하고 있는데이 오류가 무엇인지 모릅니다.이 Entity Framework 오류로 나를 도와 줄 수 있습니까?

이 코드와이 오류에 대해 도움을주십시오.

TbStudy Ts = new TbStudy(); 

int yearselect = Convert.ToInt16(cmbyear.SelectedItem); 
int weekselect = Convert.ToInt16(cmbyear.SelectedItem); 

string monthselect = cmbmonth.SelectedItem.ToString(); 
string dayselect = cmbday.SelectedItem.ToString(); 

Ts.Coursename = txtcoursename.Text; 
Ts.Time = Convert.ToInt16(txttimestudy.Text); 
Ts.Discription = txtdiscription.Text; 
Ts.Year = (from p in db.TbYears 
      where p.Year == yearselect 
      select p.Year).SingleOrDefault(); 
Ts.Month = (from p in db.TbMonths 
      where p.Month == monthselect 
      select p.Month).SingleOrDefault(); 
Ts.Weeknum = (from p in db.TbWeeks 
       where p.Week == weekselect 
       select p.Week).SingleOrDefault(); 
Ts.Day = (from p in db.TbDays 
      where p.Day == dayselect 
      select p.Day).SingleOrDefault(); 

db.AddToTbStudies(Ts); 
db.SaveChanges(); 

이 오류이 메시지는 다음 항목을 갱신하는

오류가 발생했습니다. 자세한 내용은 내부 예외를 참조하십시오.

InnerException는 :

System.Data.UpdateException가
HRESULT = -2146233087
메시지 엔트리를 업데이트하는 동안 에러가 발생되지 않은 =이었다. 자세한 내용은 내부 예외를 참조하십시오.
자료 = System.Data.Entity
스택 트레이스 :
System.Data.EntityClient.EntityAdapter.Update에서 System.Data.Mapping.Update.Internal.UpdateTranslator.Update (IEntityStateManager에서 StateManager, IEntityAdapter 어댑터)에 (IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges (SaveOptions options) at System.Data.Objects.ObjectContext.SaveChanges() at Office_Of_Planning.IDEU_Form.btnInsert_Click (Object sender, EventArgs e) in C : \ Users \ Pooya \ Documents \ Visual Studio 2010 \ Projects \ 그림을 \ Office_Of_Planning \ Office_Of_Planning \ IDEU_Form.cs : 줄 49 at System.Windows.Forms.Control.OnClick (EventArgs e) at System.Windows.Forms.Button.OnClick (EventArgs e) at System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp (메시지 &m, MouseButtons 단추, Int32 클릭 수)에 System.Windows.Forms.Button.WndProc System.Windows.Forms.ButtonBase.WndProc (메시지 & m) 에서 System.Windows.Forms.Control.WndProc (메시지 & m) 에서 (메시지 & m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage (메시지 &m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc (메시지 &m) at System입니다. System.Windows.Forms.Application.ComponentManager.System에서 Windows.Forms.NativeWindow.DebuggableCallback (HWND를 IntPtr, INT32의 MSG,을 IntPtr의 WPARAM, LPARAM을 IntPtr의) System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW에서 (MSG & MSG) . System.Windows.Forms.Application.ThreadContext에서 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (INT32 이유 ApplicationContext는 컨텍스트)에 Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (dwComponentID을 IntPtr, INT32 이유, INT32 pvLoopData) .RunMessageLoop (Int32 이유, ApplicationContext 컨텍스트)at System.Windows.Forms.Application.RunDialog (Form form) at System.Windows.Forms.Form.ShowDialog (IWin32Window owner) at System.Windows.Forms.Form.ShowDial Office_Of_Planning.Main_Form의 og() Office System의 ProjectStripMenuItem_Click (Object sender, EventArgs e)은 C : \ Users \ Pooya \ Documents \ Visual Studio 2010 \ Projects \ Office \ Office \ Office_Of_Planning \ Main_Form.cs 파일의 라인 45 에 있습니다. Windows.Forms.ToolStripItem.RaiseEvent (Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.의 OnClick (있는 EventArgs E)에서 System.Windows.Forms.ToolStripItem.HandleClick (EventArgs입니다 E)에서 System.Windows.Forms.ToolStripItem.HandleMouseUp (MouseEventArgs 형식 E)에서 System.Windows.Forms.ToolStripItem.FireEventInteractive (있는 EventArgs 즉, ToolStripItemEventType가 System.Windows.Forms.ToolStripItem.FireEvent에서 )이 충족 (EventArgs입니다 전자, ToolStripItemEventType가 System.Windows.Forms.ToolStripDropDown.OnMouseUp에서 System.Windows.Forms.ToolStrip.OnMouseUp (MouseEventArgs 형식 MEA) 에서 )이 충족 (MouseEventArgs 형식 MEA) at System.Windows.Forms.Control.WmMouseUp (메시지 &m, MouseButtons 단추, Int32 클릭) at System.Windows.Forms.Control.WndProc (메시지 &m) at System. Windows.Forms.ScrollableControl.WndProc (메시지 & m) System.Windows.Forms.ToolStrip.WndProc에서 (메시지 & m) System.Windows.Forms.ToolStripDropDown.WndProc에서 (메시지 & m) System.Windows에서 . Forms.Control.ControlNativeWindow.OnMessage (메시지 & m) System.Windows.Forms.NativeWindow.DebuggableCallback에서 System.Windows.Forms.Control.ControlNativeWindow.WndProc (메시지 & m) 에서 (HWND를 IntPtr, INT32의 MSG,을 IntPtr의 WPARAM , IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW (MSG & msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.U nsafeNativeMethods.IMsoComponentManager.FPushMessageLoop (IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner (Int32 이유, ApplicationContext 컨텍스트) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 이유, ApplicationContext 컨텍스트) at System.Windows.Forms.Application.Run (양식 mainForm) at Office_Of_Planning.Program.Main() C : \ Users \ Pooya \ Documents \ Visual Studio 2010 \ Projects \ Office \ Design \ Office_Of_Planning \ Program.cs : 줄 18 at System.AppDomain._nExecuteAssembly (RuntimeAssembly assembly, String [] args) at System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args) at Microsoft.VisualStudio .HostingProcess.HostProc.RunUsersAssembly()에서 System.Threading.ExecutionContext.RunInternal System.Threading.ThreadHelper.ThreadStart_Context (객체 상태)에서 (ExecutionContext에 ExecutionContext에, ContextCallback 콜백, 부울 preserveSyncCtx를 상태 객체)에 System.Threading.ExecutionContext (ExecutionContext executionContext, ContextCallback 콜백, 개체 상태) System.Threading.ThreadHelper.ThreadStart ( )에서 InystemException : 시스템. Data.SqlClient.SqlException HResult = -2146232060 메시지 = IDENTITY_INSE 인 경우 테이블 'TbStudy'의 ID 열에 명시 적 값을 삽입 할 수 없습니다. RT가 OFF로 설정됩니다. 출처 = 닷넷하는 SqlClient 데이터 공급자 있는 ErrorCode = -2146232060 클래스 = 16 LINENUMBER = 1 개 번호 = 544 절차 = "" 서버 =. 상태 = 1 스택 트레이스 : System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning에서 System.Data.SqlClient.SqlConnection.OnError (SQLEXCEPTION 예외 부울 breakConnection, 액션 1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action 1 wrapCloseInAction) (TdsParserStateObject stateObj 부울 callerHasConnectionLock 부울 asyncClose에서 ) (System.Data.SqlClient.TdsParser)TryRun (RunBehavior runBehavior, SqlCommand를 cmdHandler, SqlDataReader 개체 데이터 스트림, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, 부울 & dataReady) System.Data.SqlClient.SqlCommand.FinishExecuteReader에서 (SqlDataReader 개체 DS, RunBehavior runBehavior, 문자열 resetOptionsString)의 System.Data.SQLClient에서 . SqlCommand.RunExecuteReaderTds (CommandBehavior를 cmdBehavior, RunBehavior runBehavior, 부울 returnStream, 부울 비동기, INT32 제한 시간, 작업 & 작업, 부울 asyncWrite, SqlDataReader 개체의 DS) System.Data.SqlClient.SqlCommand.RunExecuteReader에서 (CommandBehavior를 cmdBehavior, RunBehavior runBehavior, 부울 returnStream, String 메서드, TaskCompletionSource 1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource 완료, String methodName, 부울 sendToPipe, Int32 시간 초과, 부울 asyncWrite) at Sy stem.Data.SqlClient.SqlCommand.ExecuteNonQuery() 에서 System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute (UpdateTranslator 변환기, EntityConnection 연결, 사전 2 identifierValues, List 1 generatedValues) at System.Data.Mapping.Update.Internal. UpdateTranslator.Update (IEntityStateManager에서 StateManager, IEntityAdapter 어댑터) 의 InnerException는 :

+0

내부 예외를 게시 할 수 있습니까? – Marco

+0

자세한 내용은 내부 예외가 보입니까? – SLaks

+0

예 내부 예외를 보았지만이 오류에 대해 도움을주지 않았습니다. – user3568937

답변

0

예외는 식별 C 럼에 대한 명시 적 값을 삽입하려고하는 것을 말한다.

Cannot insert explicit value for identity column in table 'TbStudy' 

아마도 테이블 디자인을보고 키가 무엇인지 확인할 필요가 있습니다.

+0

아마도 OP에 신원 키 열에'DatabaseGeneratedOption.Identity'로 주석을달라고해야 할 것입니다. –

+0

대답을 유용하게 사용했는지 여부를 알려주십시오. 필요한 추가 정보가 있습니까? 의견을 제공하십시오. –

관련 문제