0

I can read all of the value except 'one'.

This is my code:

OleDbConnection oledb_con = new OleDbConnection(strCon);

oledb_con.Open();

OleDbCommand oledb_com = new OleDbCommand("SELECT * FROM [sheet1$]", oledb_con);

OleDbDataReader oledb_dr = oledb_com.ExecuteReader();

while (oledb_dr.Read())
{                
       ActionList.Add(oledb_dr[0].ToString().Trim());
       ValueList.Add(oledb_dr[1].ToString().Trim());
}

oledb_dr.Close();
oledb_con.Close();

the ValueList[0] always show nothing,but other ValueList's member can read.

And theActionList[0] can read.

why cannot the first value be read.

And how can I solve it?

7
  • Well do you have any values available (maybe the row is blank or its header row so ignored) Commented Apr 16, 2012 at 8:42
  • yes i can edit excel by myself. if header row ignored another column's header row should not be worked but only one column has problem. =( Commented Apr 16, 2012 at 8:44
  • 1
    If your column is mixtype . maybe you need add "MaxScanRows=0;IMEX=1;" in your strcon . Commented Apr 16, 2012 at 9:02
  • already add, but still have the same problem. Commented Apr 16, 2012 at 9:10
  • if you have HDR=Yes in your connectionstring, try by specifying the column names on your select statement instead of *. Ex: SELECT MyColumn1, MyColumn2 FROM [sheet1$] Commented Apr 16, 2012 at 9:56

1 Answer 1

1

Have you checked if the value is not null? On null reading value as string fails.

oledb_dr.IsDbNull(1) ? "" : oledb_dr[1].ToString().Trim()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.