How to add csv file in a 2d array vb.net? -


user, 1,2,3,4,5,6,7,8,9  joe, 34,3,32,1,3  john, 32,2  tom, 98,34,23  dave, 56, 53, 32,1,22,6,5 

i have csv file put in 2d array.

private sub getelement()     'read data cv file     try         dim filein string = "mel.csv"         dim filerows(), filefields() string         dim count integer = 0         textbox.text = string.empty         if file.exists(filein)             dim filestream streamreader = file.opentext(filein)             filerows = filestream.readtoend().split(environment.newline)             integer = 0 filerows.length - 1                 filefields = filerows(i).split(",")                 if filefields.length >= 2                     x integer = 0 filefields.length - 1                         if x = 0                             e integer = 0 filefields.length                                 ele.add(filefields(e))                                 listbox.items.add(ele(e))                             next                         end if                     next                     count = count + 1                 end if             next         else             textbox.text = filein & " not found."         end if     catch ex exception         textbox1.text = ex.message     end try end sub 

i able receive first line , have added list box. in mainwindow class have declared 2 list of string store column , rows.

try this....

imports system.data.oledb  public class form1  private sub form1_load(sender object, e eventargs) handles mybase.load     dim folder = "path csv folder (do not include file name here)"     dim cnstr = "provider=microsoft.jet.oledb.4.0;data source=" & folder & ";extended properties=""text;hdr=no;fmt=delimited"";"     dim dt new datatable     ' change test.csv csv file name here     using adp new oledbdataadapter("select * [test.csv]", cnstr)         try             adp.fill(dt)         catch ex exception         end try     end using      datagridview1.datasource = dt end sub  end class 

this import csv file display straight datagridview control (list box has problem columns)... hope helps


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -