I wrote an article earlier about how to view the database file through the
TreeView control and
ListView control with the use of ADO objects. I wrote the code in that article using VB6. To read the code in VB6, click here.
Now I wrote the code using VB.NET and C#. Therefore, I use ADO.NET instead of ADO.
This article show how to:
- Use some classes from
Table names and
ListView with Records of selected
I created two projects, I wrote the code of one using C# (2003) and the code of the other using VB.NET (2003).
The demonstration Project has one Form. I add the following controls to my Form (frmDataView):
- Two Labels (lblDatabase) to display the file name and (lblTableName) to display the table name
- Two Buttons, one (btnLoadData) to connect with database file, the other (btnExit) to end show
ImageList (ImageList1) to load some icons
TreeView (tvData) and
About the Code
I have used two arrays as
ArrayList to save tables name and fields name:
tblArray to save tables name and
fldArray to save fields name.
The code contains the following procedures:
DataConnection() .. to connect with database file
GetTables() .. to fill
tblArray with tables name
GetFields() .. to fill
fldArray with fields name
FillTreeView() .. to fill TreeView control with tables name and fields name
FillListView() .. to fill ListView control with records of selected table
Please read the full code in the Form (frmDataView).
The file (prjVB.zip) contains the VB.NET project.
The file (prjC.zip) contains the C# project.
I hope this article is useful and helps you to display Tables, Fields and Records from database file to
ListView. Please tell me if you have any ideas or if you find any problems. Thanks to CodeProject and thanks to all.
- 11th June, 2010: Initial post