/// <summary> /// import from sheet TypPZS /// </summary> /// <param name="excel_con"></param> private void ImportTypPZS(OleDbConnection excel_con) { DataTable dtExcelData = new DataTable(); //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default. dtExcelData.Columns.AddRange(new DataColumn[5] { new DataColumn("Id", typeof(int)), new DataColumn("Kod", typeof(string)), new DataColumn("Nazev", typeof(string)), new DataColumn("DatumOd", typeof(DateTime)), new DataColumn("DatumDo", typeof(DateTime)) }); using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [TypPZS$]", excel_con)) { oda.Fill(dtExcelData); foreach (DataRow row in dtExcelData.Rows) { _dataConnector.CreateTypPZS((string)row["Kod"], (string)row["Nazev"], (DateTime)row["DatumOd"], row.IsNull("DatumDo") ? null : (DateTime?)row["DatumDo"]); } } }