简体   繁体   中英

how to store image path in mysql database using C#

i am developing windows form to save an image path in database and then to retrieve that image using its path stored in database. My code saves the path but the slashes "/" are excluded. so help me how to save the image path correctly. Here is my code.

private void button3_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                imagePath = openFileDialog1.FileName.ToString();
                label23.Text = openFileDialog1.SafeFileName.ToString();
                Image thumbnail = Image.FromFile(openFileDialog1.FileName).GetThumbnailImage(214, 186, () => false, IntPtr.Zero);
                pictureBox1.Image = thumbnail;
                command.CommandText = "insert into student values ('imagePaht')";
                con.Open();
                command.Connection = con;
                command.ExecuteNonQuery();
                con.Close();

            }
        }

Use @ so the slashes are not removed. Another route is to double them, but that's not a good way.

command.CommandText = @"insert into student values ('imagePaht')";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM