hi,
i'm working with sqlserver2000.i want to insert a picture in database.follow ing code used in my project but have an error:
exception:
i'm working with sqlserver2000.i want to insert a picture in database.follow ing code used in my project but have an error:
Code:
using (SqlConnection con = new SqlConnection("server=(local);database=pubs;integrated security=true"))
{
SqlCommand cmd = new SqlCommand("insert into tb (name,val) values (@name,@val)", con);
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] val = ms.GetBuffer();
ms.Close();
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = txtName.Text;
cmd.Parameters.Add("@val", SqlDbType.Binary).Value = val;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
String or binary data would be truncated.
The statement has been terminated.
The statement has been terminated.