Reputation: 25
I have a database with a table containing 3 columns. I would like to extract data from that table and add to a list.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
OleDbCommand parancs = kapcsolat.CreateCommand();
parancs.CommandText = "select hossz from artandbihark";
kapcsolat.Open();
OleDbDataReader reader = parancs.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
dataGridView1.DataSource = dt;
List<double> tavolsag = new List<double>();
for (int i = 0; i < dt.Rows.Count; i++)
{
tavolsag.Add(Convert.ToDouble(dt.Rows[i]));
}
kapcsolat.Close();
}
But I cannot convert dt.Rows[i]
to double. How can I finish the above code to add the data correctly?
Upvotes: 1
Views: 72
Reputation: 7465
You only have one property in your DataRow, so that's the 0th property.
tavolsag.Add(Convert.ToDouble(dt.Rows[i][0]));
Upvotes: 1