如何将 acces 数据库的字段表放入列表框中?
需要创建一个表单,在其中我必须浏览和打开 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 个列表框!
第一个显示数据库的表名称<-----到这里就完成了!!!!
第二步,点击表名时显示字段名!!!---> 完成! 第三步在单击字段时显示属性!!!---> 完成!
v 可以编辑属性值,然后单击“保存”按钮,它应该更新数据库!
need to create a form in which i hav to browse and open mdb files ---> i did this part usin oprnfile dialogue!
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();
}
this is my code so far!!!
now i need to make 3 list boxes!!
1st one to display the table names of the db<-----done till here!!!!
2nd to to display field names when clicked on table name!!!---> to b done!
3rd to display attributes on fiels on clickin on it!!!---> to b done!
v can edit the attribute values and on clickin of save button it should update the database!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查 schemaTable 对象的列数组:
Check the columns array of your schemaTable object: