使用数据库时隐藏Interop Access 2007窗口 [英] Hiding an Interop Access 2007 window when working with a DB

查看:65
本文介绍了使用数据库时隐藏Interop Access 2007窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个程序来打开几个mdb或xls文件,读取表和列名,合并其中的一些(选定的)并生成一个新的mdb文件.在目标系统上将有MS Access可用,我正在为以下应用程序编写应用程序: Access2007.所有数据库内容都应向用户隐藏.

I want to write a programm that opens several mdb or xls files, reads the table and column names, merges some (selected ones) of them and produces a new mdb file. On the target system there will be MS Access available, I'm writing the application for/with Access 2007. All database stuff should be hidden from the user.

尽管我已经对C,C ++和Java有所了解,但是整个Access内容以及使用C#进行编程对我来说还是很新的.因此,我读到的有关访问Access文件的知识(现在让我们忽略Excel文件),有一些选项可供选择

The whole Access stuff as well as programming with C# is pretty new to me although I have already some experience with C, C++ and Java. So, what I read about accessing Access files (let's ignore the Excel files for now), there are the options to

-使用Microsoft.Office.Interop.Access东西并通过C#应用程序控制MS Access应用程序

- use the Microsoft.Office.Interop.Access stuff and control the MS Access application through the C# application

-使用System.Data.OleDb东西并连接到数据库本身.

- use the System.Data.OleDb stuff and connect to the database itself.

 

我认为使用第一次尝试会更容易,因为您不必使用查询,但可以使用ApplicationClass对象为您提供的对象.首先,这种想法对我想要实现的目标是错误的吗?

My thought was that it was easier to use the first attempt, because you don't have to work with queries but can work with the objects that the ApplicationClass object gives you. First of all, is this thought wrong for what I want to achieve?

所以我花了一段时间研究并设法告诉Access打开我的数据库(northwind.mdb):

So I worked on this for some time and managed to tell Access to open my database (the northwind.mdb):

private void button1_Click(object sender, EventArgs e) {
	ApplicationClass accessApp;
	Database currentDB;

	accessApp = new ApplicationClass();

	accessApp.Visible = false; //doesn't do a thing
	accessApp.UserControl = false; //doesn't do a thing either
				
	accessApp.OpenCurrentDatabase(@"C:\prog\test.mdb", true, null);

	currentDB = (Database) accessApp.CurrentDb();

	for (int i = 0; i < currentDB.TableDefs.Count; i++) {
		combobox1.Items.Add(currentDB.TableDefs[i].Name);
	}

	for (int i = 0; i < currentDB.TableDefs[0].Fields.Count; i++) {
		combobox2.Items.Add(currentDB.TableDefs[0].Fields[i].Name);
	}

	accessApp.CloseCurrentDatabase();
	accessApp.Quit(AcQuitOption.acQuitSaveAll);
	System.Runtime.InteropServices.Marshal.ReleaseComObject(accessApp);

	accessApp = null;
}

所以我要做的是打开数据库,获取所有表的名称,将它们填充到组合框中,获取第一个表的所有列名称,然后将它们填充在另一个组合框中.这很好用,但是:

So what I want to do is to open the database, get the names of all tables, fill them into a combo box, get all the column names of the first table and fill them in another combo box. This works well, but:

如何隐藏Access 2007窗口?

How to I hide the Access 2007 window?

我认为这将由一行完成

accessApp.Visible = false
;

推荐答案

我刚刚安装了MS Access 2003 SP3,它是同一回事:(我使用的Access实例始终可见.有可能隐藏窗口吗?
I just installed MS Access 2003 SP3 and it's the same thing :( The Access instance I use is visible the whole time. Isn't there a possibility to hide the window?


这篇关于使用数据库时隐藏Interop Access 2007窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆