VB.NET Excel file not connecting with virtual datagridview -


i trying write module in vb.net application, isn't working properly. trying create datagridview, , load excel file it. however, excel isn't loading in it.

code below

imports microsoft.office imports microsoft.office.interop imports system.data.oledb imports system.net.mail  module m_islshpptsplit dim uploadfilepath string dim uploadfilename string  dim dgv1 datagridview dim dgv2 datagridview  public sub loadfile()     dgv1 = new datagridview     dgv2 = new datagridview     try         dim filedialog openfiledialog = new openfiledialog()         dim path string         filedialog.title = "select file"         filedialog.initialdirectory = "desktop"         filedialog.restoredirectory = true         if filedialog.showdialog() = windows.forms.dialogresult.ok             path = filedialog.filename         else             path = nothing         end if         uploadfilepath = filedialog.filename         uploadfilename = system.io.path.getfilename(filedialog.filename)         dim dtsheet1 new datatable          if not path = nothing             using cn new system.data.oledb.oledbconnection                 dim builder new oledbconnectionstringbuilder _                     { _                         .datasource = path, _                         .provider = "microsoft.ace.oledb.12.0" _                     }                 builder.add("extended properties", "excel 12.0; imex=1;hdr=yes;")                 cn.connectionstring = builder.connectionstring                  cn.open()                  using cmd oledbcommand = new oledbcommand {.connection = cn}                     cmd.commandtext = "select * [fnac$]"                     dim dr system.data.idatareader = cmd.executereader                      dtsheet1.load(dr)                     dgv1.datasource = dtsheet1                 end using             end using             messagebox.show(dgv1.rowcount)             messagebox.show("done")         end if     catch ex exception         messagebox.show(ex.message)     end try     splitfile() end sub 'loadfile 

after that, need perform calculations etc, line

messagebox.show(dgv1.rowcount) 

actually returns 0. excel file has 316 lines in it. how can data stick new dgv?

i think problem stems not adding dgv1 control collection (the datasource attached in no rows have been created display). if messagebox.show(dtsheet1.rows.count) notice count proving data being read in. playing around, added form1.controls.add(dgv1) before messagebox.show(dgv1.rowcount) , produced received proper count.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -