You are on page 1of 1

private void button1_Click(object sender, EventArgs e)

{
openFileDialog1.Title = "Lütfen Dosya Seçiniz";
openFileDialog1.Filter = " (*.xlsx)|*.xlsx";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string dosya_adres = openFileDialog1.FileName; OleDbConnection con
= new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
dosya_adres + ";Extended Properties=Excel 12.0");
con.Open();
string sql = "SELECT * from [Sayfa1$A1:A5000] ";
OleDbCommand veri2 = new OleDbCommand(sql, con); OleDbDataReader dr
= null;
dr = veri2.ExecuteReader();

while (dr.Read())
{
if (dr[0] != "")
{
listBox1.Items.Add(dr[0].ToString());
}
else
{
break;
}
}
con.Close();
}
}

You might also like