2013-02-25 36 views
2

我在做一個項目,我開始測試它的一部分。我意識到我有一個小問題,但無法理解它。我試圖插入一些數據到數據庫,有一列是nvarchar(4000)。但每當我嘗試插入任何長度的字符串,它只會插入255個字符。爲什麼只需要255個字符?asp.net只在數據庫中插入255個字符

這裏是我的代碼,

dbCommand = db.GetStoredProcCommand("New_Post"); 
     db.AddInParameter(dbCommand, "PostHeader", DbType.String, txt_post_header.Text.Trim()); 
     db.AddInParameter(dbCommand, "PostBody", DbType.String, txt_post_body.Text.Trim()); 
     db.AddInParameter(dbCommand, "UserId", DbType.Guid, new Guid(Session["SessionUserID"].ToString())); 
     db.AddInParameter(dbCommand, "PollDescription", DbType.String, txt_poll.Text); 
     db.AddInParameter(dbCommand, "CityId", DbType.Int16, 1); 
     db.AddInParameter(dbCommand, "SpecialtyID", DbType.Int16, Convert.ToInt16(Session["SessionSpecialityId"].ToString())); 
     db.ExecuteNonQuery(dbCommand); 
+1

存儲過程New_Post的參數類型是什麼? nvarchar(4000)呢? (此外......它在裏面做什麼?) – 2013-02-25 13:46:13

+0

**存儲過程**是否可能將參數限制爲255個字符?否則:你可以**使用'db.AddInParameter(...)'爲你的'DbType.String'參數指定一個長度** - 也許這個默認值爲255,除非你另有指定.... – 2013-02-25 13:48:04

+0

你是男人: ) 非常感謝你。在Procdure中,聲明瞭255. – 2013-02-25 13:49:09

回答

0

既然你是不是有限制聲明參數,你唯一的2個選項是數據庫領域擁有256限制或參數的存儲過程,檢查一下,你應該解決你的問題。

相關問題