Click here to Skip to main content
12,622,675 members (26,880 online)
Click here to Skip to main content
Add your own
alternative version

Stats

72K views
7.9K downloads
36 bookmarked
Posted

Display Database using TreeView and ListView with ADO.NET

, 11 Jun 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
Using ADO.NET in Visual Studio.NET to display database in TreeView and ListView
img067.JPG

Introduction

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 System.Data.OleDb Namespace
  • Populate TreeView with Table names and Field names
  • Populate ListView with Records of selected Table

Background

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 ListView (lvData)

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).

Remarks

The file (prjVB.zip) contains the VB.NET project.
The file (prjC.zip) contains the C# project.

Final Words

I hope this article is useful and helps you to display Tables, Fields and Records from database file to TreeView and ListView. Please tell me if you have any ideas or if you find any problems. Thanks to CodeProject and thanks to all.

Mostafa Kaisoun
M_Kaisoun@hotmail.com

History

  • 11th June, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralMy vote of 5 Pin
evry1falls11-Mar-13 5:56
memberevry1falls11-Mar-13 5:56 
GeneralRe: My vote of 5 Pin
Mostafa Kaisoun13-Mar-13 8:37
memberMostafa Kaisoun13-Mar-13 8:37 
GeneralRe: My vote of 5 Pin
evry1falls13-Mar-13 10:01
memberevry1falls13-Mar-13 10:01 
GeneralRe: My vote of 5 Pin
evry1falls15-Mar-13 14:10
memberevry1falls15-Mar-13 14:10 
Questionwhat about do it with sql server compact Pin
Mostafa Abd El-Salam Maklad14-Nov-12 5:05
memberMostafa Abd El-Salam Maklad14-Nov-12 5:05 
AnswerRe: what about do it with sql server compact Pin
Mostafa Kaisoun13-Mar-13 8:31
memberMostafa Kaisoun13-Mar-13 8:31 
Questionusing Sql database Pin
vincezed6-Apr-11 11:26
membervincezed6-Apr-11 11:26 
AnswerRe: using Sql database Pin
Mostafa Kaisoun6-Apr-11 15:10
memberMostafa Kaisoun6-Apr-11 15:10 
GeneralRe: using Sql database Pin
vincezed7-Apr-11 8:45
membervincezed7-Apr-11 8:45 
GeneralRe: using Sql database Pin
Mostafa Kaisoun9-Apr-11 20:36
memberMostafa Kaisoun9-Apr-11 20:36 
GeneralRe: using Sql database Pin
Mostafa Kaisoun10-Apr-11 20:05
memberMostafa Kaisoun10-Apr-11 20:05 
GeneralRe: using Sql database Pin
vincezed11-Apr-11 8:05
membervincezed11-Apr-11 8:05 
GeneralRe: using Sql database Pin
Mostafa Kaisoun12-Apr-11 13:12
memberMostafa Kaisoun12-Apr-11 13:12 
GeneralRe: using Sql database Pin
vincezed13-Apr-11 8:23
membervincezed13-Apr-11 8:23 
GeneralRe: using Sql database Pin
Mostafa Kaisoun13-Apr-11 13:27
memberMostafa Kaisoun13-Apr-11 13:27 
GeneralRe: using Sql database Pin
vincezed14-Apr-11 7:21
membervincezed14-Apr-11 7:21 
GeneralRe: using Sql database Pin
Mostafa Kaisoun15-Apr-11 18:17
memberMostafa Kaisoun15-Apr-11 18:17 
GeneralRe: using Sql database Pin
vincezed16-Apr-11 9:11
membervincezed16-Apr-11 9:11 
GeneralRe: using Sql database Pin
Mostafa Kaisoun16-Apr-11 15:32
memberMostafa Kaisoun16-Apr-11 15:32 
GeneralRe: using Sql database Pin
vincezed17-Apr-11 2:23
membervincezed17-Apr-11 2:23 
GeneralRe: using Sql database Pin
vincezed18-Apr-11 4:35
membervincezed18-Apr-11 4:35 
GeneralRe: using Sql database Pin
Mostafa Kaisoun18-Apr-11 12:34
memberMostafa Kaisoun18-Apr-11 12:34 
GeneralRe: using Sql database Pin
Mostafa Kaisoun18-Apr-11 15:39
memberMostafa Kaisoun18-Apr-11 15:39 
GeneralRe: using Sql database Pin
vincezed22-Apr-11 10:46
membervincezed22-Apr-11 10:46 
GeneralRe: using Sql database Pin
Mostafa Kaisoun22-Apr-11 13:50
memberMostafa Kaisoun22-Apr-11 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 11 Jun 2010
Article Copyright 2010 by Mostafa Kaisoun
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid