473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

insert picture in db

hi,
i'm working with sqlserver2000.i want to insert a picture in database.following code used in my project but have an error:
Expand|Select|Wrap|Line Numbers
  1. using (SqlConnection con = new SqlConnection("server=(local);database=pubs;integrated security=true"))
  2. {
  3. SqlCommand cmd = new SqlCommand("insert into tb (name,val) values (@name,@val)", con);
  4.  
  5. MemoryStream ms = new MemoryStream();
  6. pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
  7. byte[] val = ms.GetBuffer();
  8. ms.Close();
  9.  
  10. cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = txtName.Text;
  11. cmd.Parameters.Add("@val", SqlDbType.Binary).Value = val;
  12.  
  13. con.Open();
  14. cmd.ExecuteNonQuery();
  15. con.Close(); 
  16.  
  17. }
  18.  
exception:

String or binary data would be truncated.
The statement has been terminated.
Apr 22 '09 #1
0 965

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Patrick | last post by:
How do you insert a jpg picture from file on to an area of a dialog box I can do this using picturebox to insert a jpg picture onto a form, but the picturebox control is not available for a...
1
by: blue_nirvana | last post by:
I have a form that a user loads pictures onto using picture boxes. I want to be able to insert those pictures into a Word document. How can I insert a picture into a Word document through...
1
by: Fabian | last post by:
Hi all, I need an example to insert an Picture in an opend Word Document. My Code doesn t work. I tried : object vk_missing = Type.Missing;...
3
by: andrewtayloruk | last post by:
I'm a newbie when it come to things php and i'm having a bit of trouble. I'm trying to insert data from an html form into a mysql database and can't get it to work. Just a few bits about my...
8
by: andrewtayloruk | last post by:
Hi i was wondering if anyone could help.... I have made a little script that puts whatever a user enters into a mysql database. As well as the forms my script has an image input that uploads an image...
5
by: coolminded | last post by:
hi everyone i have a problem, i just export the data from data grid to the word file, but now the problem is i want to insert the picture in the word with the path name in the grid. for ex; i...
2
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php"...
3
by: abspring | last post by:
Hi I am a technology teacher/support person at an elementary school. I have created a database in which I need to insert a picture for each of our 650+ students. I have a table of student...
3
by: JFKJr | last post by:
Hello everyone, I am trying to insert a picture in an excel spreadsheet cell using Access VBA. The following excel VBA code is working perfectly fine and I am able to insert picture in "A1" cell....
4
by: lena1342 | last post by:
Hi Everyone! I tried to insert a picture in specific cells and I have coded a small VBA for Excel 2007. Unfortunately the macro only opens and inserts a picture in the active sheet but it should...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.