我正在參加考試自制論壇,我剛剛發現了一個奇怪的問題。 如果我輸入超過50個字符到textarea爲發佈內容,數據被提交到數據庫,但是當我嘗試顯示帖子時,由於約束異常,我的發佈對象失敗。我如何輸出更多文字?
有人知道可能是什麼原因造成的嗎?
數據庫中的字段是文本類型。
Line 139: DataTable daldata = dalPosts.GetDataFirstPostInThreadId(id);
Line 140:
Line 141: Post postObject = new Post(Convert.ToInt32(daldata.Rows[0]["id"]), Convert.ToInt32(daldata.Rows[0]["fk_user_id"]), Convert.ToInt32(daldata.Rows[0]["fk_thread_id"]), daldata.Rows[0]["contents"].ToString(), Convert.ToDateTime(daldata.Rows[0]["submissiondate"]), Convert.ToBoolean(daldata.Rows[0]["isdeleted"]));
Line 142: return postObject;
Line 143:
錯誤的詳細信息:
System.Data.ConstraintException was unhandled by user code
Message=Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
Source=System.Data
StackTrace:
at System.Data.DataTable.EnableConstraints()
at System.Data.DataTable.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at DALTableAdapters.PostTableAdapter.GetDataFirstPostInThreadId(Int32 threadid) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\bp2010\62c352df\ee467897\App_Code.rvxbfwcl.5.cs:line 7570
at DataBLL.PostBLL.ObjectFirstInThread(Int32 id) in c:\Users\Stjerneklar\Documents\My Dropbox\SP2010 Ballonparken\BP2010\App_Code\DataBLL\PostBLL.cs:line 139
at DataBLL.Thread..ctor(String name, Int32 id, Int32 fk_category_id) in c:\Users\Stjerneklar\Documents\My Dropbox\SP2010 Ballonparken\BP2010\App_Code\DataBLL\ThreadBLL.cs:line 67
at DataBLL.threadBLL.SelectByCategoryId(Int32 fk_category_id) in c:\Users\Stjerneklar\Documents\My Dropbox\SP2010 Ballonparken\BP2010\App_Code\DataBLL\ThreadBLL.cs:line 176
at ForumThreads.createThread(Object sender, EventArgs e) in c:\Users\Stjerneklar\Documents\My Dropbox\SP2010 Ballonparken\BP2010\ForumThreads.aspx.cs:line 49
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:
我有可能會影響事物的相關表沒有其他內容,如果我縮短文本一切工作正常。
編輯: 最後(交付作業前一晚)找出它 違規字段被定義爲在我的數據集中具有50個字符的最大值。
問題是很模糊的,但確切的錯誤信息會是一個很好的起點,如果數據已經被插入到數據庫中確定改善這個問題 – rtpHarry 2010-12-02 16:48:46
,讀會不會導致一種約束例外。你做的不只是閱讀嗎? – Oded 2010-12-02 16:50:01