Image location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mujeesh
    New Member
    • Feb 2010
    • 3

    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:ProductionIm agesimage001.jp g"

    //this is my code
    Code:
    private void button2_Click(object sender, EventArgs e)
    {
    OpenFileDialog open = new OpenFileDialog();
    
    open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
    
    if (open.ShowDialog() == DialogResult.OK)
    {
    
    pictureBox1.Image = new Bitmap(open.FileName);
    
    //I am using a class
    
    c.cmd = new MySqlCommand("SELECT COUNT(*) FROM image_table;", c.conn());
    maxVal = Convert.ToInt32(c.cmd.ExecuteScalar().ToString());
    
    
    c.conn();
    
    
    
    
    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 + "')";
    
    {
    c.cmd = new MySqlCommand(query, c.conn());
    
    //Execute command
    c.cmd.ExecuteNonQuery();
    c.conn().Close();
    
    }
    
    }
    }

    Please suggest a method to solve this problem.I am stuck,the code isn't work.
    Last edited by Curtis Rutland; Aug 4 '10, 02:23 PM. Reason: Use [CODE][/CODE] tags when posting code.
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    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().

    Comment

    • Joseph Martell
      Recognized Expert New Member
      • Jan 2010
      • 198

      #3
      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.

      Comment

      Working...