简体   繁体   中英

string or binary data would be truncated. the statement has been terminated. in c#

MemoryStream ms1 = new MemoryStream();
MemoryStream ms2 = new MemoryStream();

customer_pic_1.Image.Save(ms1,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] img_arr1 = new byte[ms1.Length];
ms1.Read(img_arr1,0,img_arr1.Length);

//ImageConverter converter = new ImageConverter();
//return (byte[])converter.ConvertTo(img_arr1, typeof(byte[]));
cmd.Parameters.AddWithValue("@a", name_txt.Text );
cmd.Parameters.AddWithValue("@b", designation_txt.Text);
cmd.Parameters.AddWithValue("@c", mobile_txt.Text);
cmd.Parameters.AddWithValue("@d", mail_txt.Text);
cmd.Parameters.AddWithValue("@e", image_path_txt.Text);
cmd.Parameters.AddWithValue("@f", img_arr1);

int result = cmd.ExecuteNonQuery();

if (result > 0)
{
   MessageBox.Show("Ur Data Inserted Successfully....$");
}
else
{
   MessageBox.Show("Sorry Ur data inserting Fail...!");
}

conx.Close();

While inserting the image I get an error:

string or binary data would be truncated. The statement has been terminated.

Please help for me .....

I tried in both ie in backend for image column image varbinary also I had used.....it is not working..........

The maximal length of the target column is shorter than the value you try to insert. Try editing the table's column for that.

And additionally please read this . Welcome to SO! :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM