winforms - How to populate listbox from excel using C# -
i have windows application. browse file , select excel file using openfiledialog control. excel file contains email id's in column a. want populate list-box excel file column values. office 2003 installed on machine. can please me out? in advance.
refer: reading excel files c#
to connect excel file need appropriate connection string:
string connstring = @"provider=microsoft.ace.oledb.12.0; data source=<yourexcelpath>; extended properties=\"excel 12.0;hdr=yes;\""; after use oledb classes query information file:
string selectcmd = "select * <sheetname>"; using(oledbconnection excelconn = new oledbconnection(connstring)) { excelconn.open(); oledbcommand command = new oledbcommand(selectcmd, excelconn); oledbdataadapter da = new oledbdataadapter(command); datatable sheetinfo = new datatable(); dataadapter.fill(sheetinfo); //do data. bind control datatable here } so need replace "yourexcelpath" path of excel file..
Comments
Post a Comment