c# - Reading Excel with OleDbDataReader - cannot read values from a specific column -


i'm working on existing c# code reading excel file oledbdatareader. can't have content cells in 2 specific columns.

this connection code:

connection = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;data source="                  + pathexcel + ";extended properties=\"excel 12.0;hdr=yes;imex=1\";"); connection.open(); 

and access content of default sheet:

tables = connection.getoledbschematable(oledbschemaguid.tables, null);   sheetsnames = datarow row in tables.rows select row["table_name"].tostring(); sql = "select * [" + sheetsnames.firstordefault() + "];"; ocmd = new oledbcommand(sql, connection); reader = ocmd.executereader(); //oledbdatareader 

so, read content, columns can't access cells content (reader["mycolumn"]). so, tried this:

while (reader.read()){    // test code, tried different ways read cell content    // it's working    string colname = reader.getname(26);    string val1 = reader[colname].tostring();    string val2 = reader.getvalue(26).tostring();     // same code, changing index 26 27    ... // empty values. bug ?? } 

if evaluate expressions "reader.getvalue(26)" returns expected value, when it's "reader.getvalue(27)" it's returns exception ("this expression causes side effects , not evaluated"), in particular it's index out of range exception. can read data next columns (29, 30...).

do have idea cause ?


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -