I have a problem with large amounts of excel data and need to display it in the datagrid, if the data is small this code works but is not effective for large amounts of data and has to wait a long time. is there a brilliant way to solve this problem?
this code
Stopwatch sw1 = Stopwatch.StartNew();
String path = "D:\\test.xlsb";
String sheet = "Sheet1";
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
path+
";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + sheet + "$]", con);
try
{
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
DataTable data = new DataTable();
sda.Fill(data);
datagrid1.ItemsSource = (System.Collections.IEnumerable)data.DefaultView;
con.Close();
sw1.Stop();
Console.WriteLine("Time taken for excel roots: {0} ms", sw1.Elapsed.TotalMilliseconds);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}