Is it possible parsing OleDbDataAdapter object into list of double if that object contains only one Column shown on a picture below?
I want to parse values from excel file and after that I want to check all values in list with foreach
and if
loops. Can someone help me with going through OleDbDataAdapter or even better converting it into list of doubles.
Column with values that are in OleDbDataAdapter object looks like this. It has few empty fields and bunch of double values.
OleDbDataAdapter is define like this:
string pathConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
OleDbConnection connection = new OleDbConnection(pathConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select [max t] from [DAYTIME CONFORT INDEX$]", connection);
It seems more convenient to use an OleDbDataReader in this context
List<double> numbers = new List<double>();
string pathConnection = "....";
using(OleDbConnection connection = new OleDbConnection(pathConnection))
using(OleDbCommand cmd = new OleDbCommand("Select [max t] from [DAYTIME CONFORT INDEX$]", connection))
{
connection.Open();
using(OleDbDataReader reader = cmd.ExecuteReader())
{
while(reader.Read())
{
if(!reader.IsDBNull(0))
numbers.Add(Convert.ToDouble(reader[0]));
}
}
}
With an OleDbDataAdapter
you are forced to load a DataTable/Dataset
to retrieve your values and then loop again over the datatable to transform the single column in a list of double