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");
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码对我有用,但不幸的是,存储在数据库中的路径不正确..存储的路径就像this(C:Users hesisDesktopREDEFENSEResourcesImagesRED1f.png),它应该像this(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);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生呢?
我需要在列表框中的搜索结果显示中隐藏文件扩展名(.jpg,.exe).有人可以帮我弄这个吗?这是我的代码.我有文本框,按钮和列表框.
button1代码:此代码在指定的路径上搜索我的文本框上的单词并在listbox1上显示:
private void button1_Click(object sender, EventArgs e)
{
x = 0;
var path = "C:\\Users\\john\\Desktop\\FLASH\\SEARCH";
listBox1.DataSource = Directory.GetFiles(path, "*" + textBox1.Text + "*")
.Select(f => Path.GetFileName(f)).ToList();
}
Run Code Online (Sandbox Code Playgroud)
listbox1代码:此代码在点击时运行搜索结果:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var fileName = listBox1.SelectedItem as string;
if (fileName != null)
{
var path = Path.Combine("C:\\Users\\thesis\\Desktop\\THESIS\\FLASH\\SEARCH", fileName);
if (x != 0)
{
Process.Start(path);
}
}
x += 1;
}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我的输出如下:"result.exe""result.jpg".我需要的输出是这样的:"结果","输出".