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?

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
Edison
  • 79
  • 1
  • 13

1 Answers1

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()
mishak
  • 33
  • 6