Error on data Insert: String or binary data would be truncated

Posted by Nisar under Regular Expressions on 9/5/2010 | Points: 10 | Views : 6280 | Status : [Member] | Replies : 3
I upload world document and insert name and bytes of doc into database.

When i insert recoed into database i got this error on ExecuteNonQuery: String or binary data would be truncated. The statement has been terminated.
This error is due to insert Fileytes field.

Con= new SqlConnection(ConStr);
cmd= new SqlCommand("INSERT INTO Files(FileName,FileBytes) VALUES (@FileName,@FileBytes)",Con);
cmd.Parameters.AddWithValue("@FileName", upFile.FileName);
cmd.Parameters.AddWithValue("@FileBytes", upFile.FileBytes);
Con.Open();
cmd.ExecuteNonQuery();
Con.Close();

Database table is like
id int
FileName varchar(50)
FileBytes varbinary(max)

Waiting for reply.
Thanks in advance




Responses

Posted by: SheoNarayan on: 9/5/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
You can read this post http://www.beansoftware.com/asp.net-tutorials/images-database.aspx or http://aspalliance.com/articleViewer.aspx?aId=140 to get help.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Nisar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Peermohamedmydeen on: 9/6/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi Nisar,

I think the FileName column in Database you have given varchar(50). Its length exceeded when you are inserting. Please check the file name length.

This error is not from FileBytes. Kindly check.

Thanks
PMM :)

Nisar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nisar on: 9/6/2010 [Member] Starter | Points: 25

Up
0
Down
Hi,
Error is not due to FileNaem. Error in on FileBytes and in database FileBytes is varbinary(max).

any idea?

Thanks



Nisar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response