.net - Converting List of String to either a Dataset or Datatable -



.net - Converting List of String to either a Dataset or Datatable -

i'm working on project involves csv file. using microsoft.jet.oledb.4.0 extract everything. however, there big numbers don't create on , "blanked" out.

so, after doing research, able find illustration stuff list. example:

dim lstexample new list(of string)().

from here utilize steamreader grab csv file , store it. since first 3 lines garbage, i'm skipping , reading rest of lines along 30 columns of comma delimited data.

my problem i'm unable lstexample either dataset or datatable. manually created list , still errors out.

the error occurs on line:

datarow(i) = itemproperties(i).getvalue(item, nothing) saying "parameter count mismatch."

any ideas list dataset/datatable?

public shared sub manualreadcsvfile(byval strfilepath string) dim lstexample new list(of string)() using reader = new streamreader("c:\sftp_target\atl-536437.csv") integer = 0 2 reader.readline() next while not reader.endofstream dim line = reader.readline() dim values = line.split(",") lstexample.add(values(0)) end while reader.dispose() end using 'dim list new list(of string)(new string() {"nile", _ ' "amazon", _ ' "yangtze", _ ' "mississippi", _ ' "yellow"}) dim dstest new dataset dstest = createdataset(lstexample) 'dstest = createdataset(list) end sub public shared function createdataset(of t)(byval list list(of t)) dataset 'list nil or has nothing, homecoming nil (or add together exception handling) if list nil orelse list.count = 0 homecoming nil end if 'get type of first obj in list dim obj = list(0).[gettype]() 'now grab properties dim properties = obj.getproperties() 'make sure obj has properties, homecoming nil (or add together exception handling) if properties.length = 0 homecoming nil end if 'it create dataset , table dim dataset = new dataset() dim datatable = new datatable() 'now build columns properties dim columns = new datacolumn(properties.length - 1) {} integer = 0 properties.length - 1 columns(i) = new datacolumn(properties(i).name, properties(i).propertytype) next 'add columns table datatable.columns.addrange(columns) 'now add together list values table each item in list 'for each item t in list 'create new row table dim datarow = datatable.newrow() 'now have iterate thru each property of item , retrieve it's value corresponding row's cell dim itemproperties = item.[gettype]().getproperties() integer = 0 itemproperties.length - 1 datarow(i) = itemproperties(i).getvalue(item, nothing) next 'now add together populated row table datatable.rows.add(datarow) next 'add table dataset dataset.tables.add(datatable) 'return dataset homecoming dataset end function

if trying parse csv file .net objects seek http://www.filehelpers.com. it's simple way parse csv files pocos or datatables.

.net dataset arraylist

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -