473,624 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert picture in db

19 New Member
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:
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 979

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

Similar topics

6
1798
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 dialog box Thanks -- Patrick
1
10314
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 automation using VB.NET? So far I am using the below: Dim oWord As Word.Application Dim oDoc As Word.Document 'Start Word oWord = CreateObject("Word.Application")
1
2821
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; wordapp.Selection.Range.InlineShapes.AddPicture(@"C:\logo.bmp", ref vk_missing, ref vk_missing, ref vk_missing);
3
4741
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 setup, i'm running an sql server locally, i've created the database, table and fields. I think what i'm missing is something that actually runs the sql query when i hit the submit button. Also, i'm aware i haven't made the data being inserted safe, i...
8
4022
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 to my webserver. The thing i'm stuck on is getting the script to input the name of the file into a field in the database. So basically the file will be uploaded and when the submit button is clicked a link to that image will be generated and put...
5
12129
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 have three fields in the data grid 1 name 2. address 3 pic path i just exported the name, address and the path name of the picture but can't insert the actual picture.
2
2567
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" method="post" name="registrationform"> Choose a shows:
3
4575
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 information with the student id as the primary key. Another table is the student photos table that has the student id and the imagename.bmp of the photo of that student and a OLE Object field for the picture image. All of the actual picture files are .bmp...
3
20764
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. But with the following Access VBA code, I am getting "Type Mismatch" error at line #13. Please kindly let me know how to solve this issue. Thanks a million in advance! Excel VBA: Sub InsertPic()
4
21288
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 add the picture in cell B3, H4 and L6 in this sheet. Could you please help me to fix the problem. thx a lot!
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.