asp.net中连接Access数据库可以用"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("DataBa/[email protected]");我想问的是在windows窗体中怎么写数据库的相对路径????
System.Web.HttpContext.Current.Server.MapPath("DataBa/[email protected]");这个在Windows窗体中不能用!!

解决方案 »

  1.   

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBa/[email protected]";
      

  2.   

    System.Web.HttpContext.Current.Server.MapPath去掉就可以了
      

  3.   

    System.Web.HttpContext.Current.Server.MapPath,这个是在WebApp中使用的,去掉就可以了。
      

  4.   

    搞错了,不好意思,我理解错了。
    应该是
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DataBa/[email protected]";
      

  5.   

    string sCon = string.Concat(//"Provider=MSDAORA.1;",
    "Password=xxx;",
    "User ID=xxx;",
    "Data Source=xxx;",
    "Persist Security Info=True");
    this.Text = sCon;
    this.listBox1.Items.Clear();
    try
    {
    //用oracle支持连接
    System.Data.OracleClient.OracleConnection ocnMain = new System.Data.OracleClient.OracleConnection(sCon);
    ocnMain.Open();
    //打开Command
    System.Data.OracleClient.OracleCommand cmdMain = new System.Data.OracleClient.OracleCommand();
    cmdMain.Connection = ocnMain;
    cmdMain.CommandText = "SELECT distinct table_name FROM cols";
    //
    System.Data.OracleClient.OracleDataReader odrMain = cmdMain.ExecuteReader();
    while (odrMain.Read())
    {
    this.listBox1.Items.Add(odrMain.GetString(0));
    this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
    Application.DoEvents();
    System.Threading.Thread.Sleep(50);
    }
    //关闭连接
    ocnMain.Close(); }
    catch(System.Exception eException)
    {
    MessageBox.Show(eException.Message.ToString());
    }********************************************************************
    *TryMyBestToKnowSomethingAboutEverythingAndEverythingAboutSomething! 
    ********************************************************************
      

  6.   

    Environment.CurrentDirectory 属性请参见获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。[C#] 
    // Change the directory to %WINDIR%                            
    Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir");        
    DirectoryInfo info = new DirectoryInfo(".");
        lock(info)
        {      
        Console.WriteLine("Directory Info:   "+info.FullName);
        }