473,410 Members | 1,872 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,410 software developers and data experts.

Image location

hi

I am using Mysql database.

I am trying to insert an image location in to my database but its not saving properly.if i choose an image "E:\Production\Images\image001.jpg"

its saving like this "E:ProductionImagesimage001.jpg"

//this is my code
Expand|Select|Wrap|Line Numbers
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. OpenFileDialog open = new OpenFileDialog();
  4.  
  5. open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
  6.  
  7. if (open.ShowDialog() == DialogResult.OK)
  8. {
  9.  
  10. pictureBox1.Image = new Bitmap(open.FileName);
  11.  
  12. //I am using a class
  13.  
  14. c.cmd = new MySqlCommand("SELECT COUNT(*) FROM image_table;", c.conn());
  15. maxVal = Convert.ToInt32(c.cmd.ExecuteScalar().ToString());
  16.  
  17.  
  18. c.conn();
  19.  
  20.  
  21.  
  22.  
  23. string query = "INSERT INTO image_table (IMAGE_NO, IMAGE_LOCATION, ASSIGN_DATE, ASSIGN_TO, ASSIGN_BY) VALUES ('" + (maxVal + 1) + "', '" + open.FileName+ "', '" + this.Assign_date.Value + "','" + Class1.AssignTo + "','" + Class1.userName + "')";
  24.  
  25. {
  26. c.cmd = new MySqlCommand(query, c.conn());
  27.  
  28. //Execute command
  29. c.cmd.ExecuteNonQuery();
  30. c.conn().Close();
  31.  
  32. }
  33.  
  34. }
  35. }

Please suggest a method to solve this problem.I am stuck,the code isn't work.
Aug 2 '10 #1
2 3397
Christian Binder
218 Expert 100+
Have you tried using parameters instead of concatenating the values to a query-string?
Like "INSERT INTO tabXy (FieldX) VALUES (@valueX)" and passing a @valueX-parameter.
I don't know how MySqlCommand-class works, but I always use that way with SqlCommand-class.

Second you can try to output your query-string after building it to see if it's already incorrected before it gets passed to new MySqlCommand().
Aug 3 '10 #2
Joseph Martell
198 Expert 128KB
I believe that your problem is with MySQL, not C#. According to my SQL pocket reference, MySQL and PostgreSQL both recognize the '\' character as an escape character by default. You will have to double-up on your '\' characters before sending them off to MySQL, or you can explicitly specify the escape character in your SQL statement using the 'ESCAPE' keyword.
Aug 4 '10 #3

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

Similar topics

3
by: Ramsey Schaffnit | last post by:
Context: I have to print personal information on a preprinted form I've never seen using a printer I've never seen. I want to use a control to overlay the PrintPreview to indicate where I've...
0
by: Hamster_Huey | last post by:
Hey guys, I've got what i think is a simple problem, yet i can't seem to find a solution. I'd like to place an image in my HTML file whose source is a hard-coded ABSOLUTE path on my harddrive: ...
2
by: me | last post by:
Hello, Is it possible to retrieve images which are not located at the default IIS location of 'Inetpub/wwwroot/images'? Another folder or other logical drive for example (redirect command?). If...
4
by: Saya | last post by:
Hello, The IIS default location for images, usually is 'Inetpub/wwwroot/images'; currently I'm using: 'picWeb.Image=GetImage(IMG_URL+filename)', where IMG_URL="http://ipadress/images", to reach...
3
by: Brian | last post by:
Is it possible to make the location of an image be outside of the wwwroot directory? I am trying to pull an image the will be different just about every time from a different server. Is this...
10
by: FX | last post by:
I wanna publish a script on my site which allows me to hide image source. i have rough idea abt it. i`ll point src to some php page like: <img src="image.php"> & in tht php wat exactly shud be...
2
by: Ruymán | last post by:
Hello!, is possible use relative path in access? for example use "photo\image1.jpg" instead of "c:\db\photo\image1.jpg", I try it but I cann't, but in Visual Basic if is possible. Other...
2
by: =?Utf-8?B?TWFubnkgQ2hvaGFu?= | last post by:
Hello Guys, Just curious over the fact if i can store Image Location in Web.Config and then how can i extract that location in HTML <td style="width:1%" align="left" valign="middle"> <img...
1
by: Mirazul Hasan | last post by:
I can store and retrieve image reference or location such as "E:\\New Folder\\Multipurpose\\image\\"+ txtname.Text + txtaccnumber.Text +".JPG"; . But I want to store original image and...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.