Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to retrive data from MSaccess and put it in listbox . . Can anyone help in this issue . .
Posted

1 solution

Exactly how you do it will depend on what you want to retirve, and how you want to display it. But, assuming it is more than just "get a string from an Access column and display it" then it needs a little more work.
Here is one way to do it:
C#
using (OleDbConnection con = new OleDbConnection(strConnect))
    {
    con.Open();
    DataTable dt = new DataTable();
    OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM MyTable", con);
    da.Fill(dt);
    myListBox.DataSource = dt;
    myListBox.DisplayMember = "NameOfColumnInDB";
    }
There are loads of others, depending on exactly what you want to do!
 
Share this answer
 
Comments
Richard.Berry100 12-Oct-13 14:37pm    
@OriginalGriff +1 for your answer. Sounds like homework.. So you may want to provide the connection string as well. Probably something like:
string strConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data source=myDB;Mode=Share Deny None;"

(Not hundreds on the connection string for Access - burned my fingers badly there and will never use it again. SQLEXpress id working wonders for me :))

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