import html table to datatable in c# -


i wanted import data html table datatable. i've read best way use html agility. code used i'm getting error

'htmlagilitypack.htmlnodecollection' not contain definition 'select' , no extension method 'select' accepting first argument of type 'htmlagilitypack.htmlnodecollection' found (are missing using directive or assembly reference?) c:\webbrowser\webbrowsercontroldialogs\mainform.cs.

this error line :

otable.rows.add(row.selectnodes("td").select(td => td.innertext).toarray()); 

any idea on how fix ? appreciated

htmlagilitypack.htmldocument doc = new htmlagilitypack.htmldocument(); var document = webbrowser1.document; var documentasihtmldocument3 = (mshtml.ihtmldocument3)document.domdocument;  var content = documentasihtmldocument3.documentelement.outerhtml;  doc.loadhtml(content);  datatable otable = new datatable(); otable.columns.add("id .", typeof(string)); otable.columns.add("art.", typeof(string)); otable.columns.add("e ram", typeof(int)); otable.columns.add("hour", typeof(string)); otable.columns.add("s", typeof(int)); otable.columns.add("ref", typeof(double));  foreach (var row in doc.documentnode.selectnodes("//tr/td")) {     otable.rows.add(row.selectnodes("td").select(td => td.innertext).toarray());     //... 

you're missing using lets use linq extension methods. add top of file:

using system.linq; 

if error value cannot null. parameter name: source when trying call row.selectnodes("td").select(..), means row.selectnodes("td") null. should correct code and/or include appropriate null checking. think want select trs @ first, , can selectnodes("td") cells.

foreach (var row in doc.documentnode.selectnodes("//tr")) {     otable.rows.add(row.selectnodes("td").select(td => td.innertext).toarray()); } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -