ตอนนี้ผมเพิ่งหัดเขียน asp.net (C#) โดยติดต่อกับ Sql server โดยใช้ SqlDataSource
โดยผมได้ทำการใช้ wizard ในการ Insert ของ Visual Web Development แล้ว พอทำการ Insert เข้าไป ปรากฎว่าได้ผลลัพธ์ ตามด้านล่างนี้ครับ
โดยผมไปดูที่ sql server ของผมนั้น ก็ได้ทำการ Set ค่าของ
Identity Specification = Yes
(Is Identity) = Yes
แล้วครับ
รบกวนผู้รู้แนะนำผมด้วยนะครับ
----------------------------------------------------------------------
Server Error in '/' Application.
Cannot insert explicit value for identity column in table 'Reply' when IDENTITY_INSERT is set to OFF.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Cannot insert explicit value for identity column in table 'Reply' when IDENTITY_INSERT is set to OFF.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[OleDbException (0x80040e14): Cannot insert explicit value for identity column in table 'Reply' when IDENTITY_INSERT is set to OFF.]
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +1209
System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +135
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +754
System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) +214
System.Web.UI.WebControls.FormView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +511
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +50
System.Web.UI.WebControls.FormViewRow.OnBubbleEvent(Object source, EventArgs e) +113
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +50
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3087
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3601
ผมลองทำเป็น
InsertCommand="INSERT INTO [Reply] ([Detail], [ReplyName]) VALUES (?, ?)"
ปรากฏว่าขึ้นข้อความนี้แทนครับ
Server Error in '/' Application.
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[OleDbException (0x80040e21): Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.]