需要创建一个表单,我可以在其中浏览和打开mdb文件--->我用oprnfile对话做了这个部分!
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog oDlg = new OpenFileDialog();
oDlg.Title = "Select MDB";
oDlg.Filter = "MDB (*.Mdb)|*.mdb";
oDlg.RestoreDirectory = true;
string dir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
oDlg.InitialDirectory = dir;
DialogResult result = oDlg.ShowDialog();
if (result == DialogResult.OK)
{
textBox1.Text = oDlg.FileName.ToString();
}
string strFileName = oDlg.FileName.ToString();
OleDbConnection cn = new OleDbConnection();
DataTable schemaTable;
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Share Deny None;Data Source="+strFileName;
cn.Open();
schemaTable = cn.GetOleDbSchemaTable(
OleDbSchemaGuid.Tables,
new Object[] { null, null, null, "TABLE" });
//List the table name from each row in the schema table.
for (int i = 0; i < schemaTable.Rows.Count; i++)
{
strTableName = schemaTable.Rows[i].ItemArray[2].ToString();
listBox1.Items.Add(strTableName);
}
//Explicitly close - don't wait on garbage collection.
cn.Close();
}
这是我的代码到目前为止!!!
现在我需要制作3个列表框!!
第一个显示数据库的表名称&lt; -----直到这里!!!!
第二个来点击表名时显示字段名称!!! ---&gt;做完了! 第三个在点击它时显示fiels上的属性!!! ---&gt;做完了!
v可以编辑属性值,点击保存按钮就可以更新数据库!!!
答案 0 :(得分:0)
检查schemaTable对象的columns数组:
for(int i=0;i<schemaTable.Columns.Length;i++)
listBox2.Items.Add(schemaTable.Columns[i].ToString());