请教个关于OdbcConnection连接怎么写相对路径的问题
如题,我现在只会写绝对路径例如:public OdbcConnection conn = new OdbcConnection( "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/Program Files/DepotBase.mdb;Uid=管理员;Pwd=123 ");
怎么才能把DBQ=后面写成相对路径啊?不要盘符啥的....我是连的Access库
我把DBQ=写成 DBQ = " + System.Windows.Forms.Application.StartupPath + "\\DepotBase.mdb; 也不好使...
或把数据库文件和程序放一起或放Bin目录下,DBQ=直接写库名也不好使,郁闷了...
哪位高人帮我下谢谢!
这个问题我问了好久了也没人能帮助我...涉及这个问题的程序已编写的差不多了,就是连接类里还是绝对路径中......郁闷啊.....
------解决方案--------------------数据库拷贝到debug下测试通过
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace MyADOTest
{
public class DataAccessTierClass
{
public OleDbConnection con;
public OleDbDataAdapter dAdapter;
public DataSet dSet;
public string conString=@ "provider=Microsoft.Jet.OLEDB.4.0;Data Source= "+Application .StartupPath+@ "\PersonDatabase.mdb ";
public bool fnGetDataConnection()
{
try
{
con = new OleDbConnection(conString);
con.Open();
dAdapter = new OleDbDataAdapter( "select * from PersonTable ", con);
dSet = new DataSet();
dAdapter.Fill(dSet, "PersonTable ");
}
catch (Exception ex)
{
MessageBox.Show( "Error: " + ex.Message);
return false;
}
return true;
}
}
}