vb.net - creating multiple datatables in for each loop -


i have following sub. have string array e.g. 3 strings (a,b,c). wanna fill datatables data excelsheets , name tables a,b,c.

sub create_dataset(byval paramarray datatablenames() string) each fileelement in datatablenames ... myconnection.open() da.fill(ds, fileelement) myconnection.close() dim dt datatable = ds.tables(fileelement) form1.datagridview1.datasource = ds.tables(0) form1.datagridview2.datasource = ds.tables(1) 

running code give me error "ds.tables(1) doesnt exist. according understanding because create 1 table (dim dt datatable = ds.tables(fileelement))and put data table on , on again. how can create table each array element?

you need explicitly add new datatable dataset's tables collection:

sub create_dataset(byval paramarray datatablenames() string)    dim dt datatable    myconnection.open()     each fileelement in datatablenames    ...        dt = new datatable(fileelement)        da.fill(dt)        ds.tables.add(dt)    next     myconnection.close()     form1.datagridview1.datasource = ds.tables(0)    form1.datagridview2.datasource = ds.tables(1) 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -