100F 求教C#的WinForm中保存相对路径到数据库???
求教C#的WinForm中保存相对路径到数据库???
private void constring(string command)
{
string cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\img.mdb;Persist Security Info=True";
OleDbConnection conn = new OleDbConnection(cn);
string updatas = command;
OleDbCommand com = new OleDbCommand(updatas, conn);
conn.Open();
com.ExecuteNonQuery();
conn.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string up = Application.StartupPath +"\\Upimage\\" + txtName.Text + ".jpg";
p1.Image.Save(up);
p1.Image = Image.FromFile(up);
string inserts = "insert into image(Imgname,Imgfile) values ('" + txtName.Text.Trim() + "','" +up+"')";
constring(inserts);
}
数据库怎样可以显示.././文件夹/文件名的相对路径呢????
------解决方案--------------------
存入資料庫Imgfile字段衹要存txtName.Text+".jpg"就好了,以後打開文件時,取出該字段值加上文件夾路徑Application.StartupPath +"\\Upimage\\" ,就可以訪問該文件了
------解决方案--------------------
Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName)