0
我正在开发Windows窗体来保存数据库中的图像路径,然后使用存储在数据库中的路径来检索该图像。我的代码保存路径,但斜线“/”被排除。所以请帮助我如何正确保存图像路径。这是我的代码。如何使用C#在mysql数据库中存储图像路径
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();
}
}
我觉得'imagePaht'是一个局部变量。它的价值究竟是什么?你需要在'CommandText'行末尾加双引号('“') –
imagePath是全局变量,对不起,我忘记了问题中的引号,但是我的查询运行并保存了条目但它不保存斜杠(“/”)。数据库中不包含斜杠,这就是为什么它不读取图像。 – Loyal