简体   繁体   English

如何使用C#将图像路径存储在mysql数据库中

[英]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. 我正在开发Windows窗体以在数据库中保存图像路径,然后使用存储在数据库中的路径检索该图像。 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')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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