private void button14_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string c = openFileDialog1.FileName;
string connString = "Server=Localhost;Database=test;Uid=root;password=root;";
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
command.CommandText = ("Insert into data (path) values('" + c + "')");
conn.Open();
command.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Success");
}
}
这段代码对我有用,但不幸的是,存储在数据库中的路径不正确.. 存储的路径是这样的(C:Users hesisDesktopREDEFENSEResourcesImagesRED1f.png
),它应该是这样的(C:P/Users/thesis/Desktop..../1f.png
)。
但是当我用这段代码检查“sr”值时.. msgbox 显示得恰到好处..
private void button14_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MessageBox.Show(openFileDialog1.FileName);
}
}
为什么会这样呢?