Arif YILMAZ
Arif YILMAZ

Reputation: 5866

asp.net only inserts 255 characters into the database

I am doing a project and I started to test a part of it. I realize that I have a small problem but cannot understand it. I am trying to insert some data to database, there is a column which is nvarchar(4000). But whenever I try to insert any length of string, It only inserts 255 chars. Why does it take only 255 characters?

here is my code,

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);

Upvotes: 2

Views: 358

Answers (1)

Luis Tellez
Luis Tellez

Reputation: 2973

Since you are not declaring the parameter with a limit, the only 2 options you have is that the database field have 256 as limit or the Parameter in your stored Procedure, check that and you should fix your problem.

Upvotes: 1

Related Questions