我的原意想将数据库中的数据表添加进下拉框中,但是下面的代码实现不了,请各位高手看看问题在哪里,麻烦告诉我该怎么修改代码。谢谢
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "数据文件(*.mdb,*.mdf)|*.mdb;*.mdf";
if (open.ShowDialog() == DialogResult.OK)
{
OleDbConnection con=new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data source="+open.FileName);
con.Open();
DataTable Mytbl = new DataTable();
Mytbl = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
foreach (int i in Mytbl.DataSet.Tables())
{
this.toolCombo1.Items.Add( Mytbl(i).TableName);
}
}
}
}
}
[此贴子已经被作者于2006-6-19 8:46:24编辑过]