read excel data line by line with c# .net

后端 未结 4 474
不思量自难忘°
不思量自难忘° 2020-12-30 09:00

Does anyone know how can I read an excel file line by line in c#.

I found this code which will return the data from excel and display a grindview in c#. However, I j

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 09:10

    you can use OleDbDataReader as below

    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
    
        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();
    
        while (reader.Read())
        {
            var val1= reader[0].ToString();
        }
        reader.Close();
    }
    

提交回复
热议问题