C# loading data from MS Access database to listbox -


public partial class form1 : form {     oledbcommand cmd = new oledbcommand();     oledbconnection cn = new oledbconnection();     oledbdatareader dr;     public form1()     {         initializecomponent();      }      private void form1_load(object sender, eventargs e)     {         cn.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\asusk450c\documents\visual studio 2010\projects\add\add\testing.accdb;persist security info=true";         cmd.connection = cn;         loaddata();      }     private void loaddata()     {         listbox1.items.clear();         listbox2.items.clear();         try         {             string q = "select * info";             cmd.commandtext = q;             cn.open();             dr = cmd.executereader();             if (dr.hasrows)             {                 while (dr.read())                 {                     listbox1.items.add(dr[0].tostring());                     listbox2.items.add(dr[1].tostring());                 }             }             dr.close();             cn.close();          }         catch (exception e)         {             cn.close();             messagebox.show(e.message.tostring());         }     } } 

this image of database: enter image description here

enter image description here

i added 2 list boxes. 2 should display data put in database doesn't. don't know wrong, path, code or database

there nothing wrong code. check if getting exceptions or pointed right database.

also check if have assigned function form1_load() form's load event

enter image description here


Comments