Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to accomplish these 5 steps which I used to be able to do without problems in VB 6.0 and Access 2000. I am now trying to do similar in VB Studio 2012 and Access 2010. I can accomplish first 2 steps, need help with remainder.

1. Navigate to and select a database
2. Upon selection of database, populate a listbox with the table names of the database
3. Upon selection of a table name in the listbox, populate several other listboxes with the fields in the database
4. In each of the secondary listboxes, select the appropriate field to access data from
5. Iterate through database, retrieving appropriate records, based on sequential order of the data from the selected fields and exporting to a Word document.

Thanks for any help you can give me.
Posted
Comments
[no name] 8-Apr-14 10:09am    
And what have you tried? What kind of problems did you encounter?

Most of what you specify is just standard database work, so I'll leave that to you to learn, but I'll point you in the direction of some parts that may be hard to find.

I'd use ADO.net , OleDb , and the ACE engine. If you have Office installed then you should have the ACE engine already, if not you can get it here: Microsoft Access Database Engine 2010 Redistributable [^]

Here's some information that should help you formulate a connection string: http://www.connectionstrings.com/access/[^]

Once you have a Connection to the database, you can get schema information (e.g. a list of tables) with:
http://msdn.microsoft.com/en-us/library/ms135982(v=vs.110).aspx[^]

or

http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.getoledbschematable(v=vs.110).aspx[^]
(This one is harder to use and is only for OleDb.)


To get the list of columns (and their types) I prefer to use a DataReader because it works with many data providers.
I create a command like "SELECT * FROM tablename WHERE 0=1", call ExecuteReader, and then access the DataReader's GetSchemaTable method to get a DataTable with the column details.
If you don't need the details, you can simply iterate the fields and use GetName
http://msdn.microsoft.com/en-us/library/system.data.idatarecord.getname(v=vs.110).aspx[^]
to build the list of column names.


I'll also include a shameless plug for my most recent article: Simplified Database Access via ADO.NET Interfaces[^]
 
Share this answer
 
Comments
Maciej Los 8-Apr-14 10:14am    
+5!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900