Click here to Skip to main content
Licence CPOL
First Posted 11 Jun 2010
Views 30,250
Downloads 3,030
Bookmarked 31 times

Display Database using TreeView and ListView with ADO.NET

By | 11 Jun 2010 | Article
Using ADO.NET in Visual Studio.NET to display database in TreeView and ListView
 
Part of The SQL Zone sponsored by
See Also
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)

About the Author

Mostafa Kaisoun



Egypt Egypt

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionusing Sql database Pinmembervincezed10:26 6 Apr '11  
AnswerRe: using Sql database PinmemberMostafa Kaisoun14:10 6 Apr '11  
GeneralRe: using Sql database Pinmembervincezed7:45 7 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun19:36 9 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun19:05 10 Apr '11  
GeneralRe: using Sql database Pinmembervincezed7:05 11 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun12:12 12 Apr '11  
GeneralRe: using Sql database Pinmembervincezed7:23 13 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun12:27 13 Apr '11  
GeneralRe: using Sql database Pinmembervincezed6:21 14 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun17:17 15 Apr '11  
GeneralRe: using Sql database Pinmembervincezed8:11 16 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun14:32 16 Apr '11  
GeneralRe: using Sql database Pinmembervincezed1:23 17 Apr '11  
GeneralRe: using Sql database Pinmembervincezed3:35 18 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun11:34 18 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun14:39 18 Apr '11  
GeneralRe: using Sql database Pinmembervincezed9:46 22 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun12:50 22 Apr '11  
GeneralRe: using Sql database Pinmembervincezed1:36 23 Apr '11  
GeneralRe: using Sql database PinmemberMostafa Kaisoun17:26 23 Apr '11  
GeneralBad habbit PinmemberManfredP196123:24 14 Jun '10  
GeneralRe: Bad habbit PinmemberMostafa Kaisoun1:29 15 Jun '10  
GeneralRemark.. PinmemberMostafa Kaisoun23:39 12 Jun '10  
GeneralThis is no .NET Code PinmemberFZelle21:53 12 Jun '10  

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

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

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