using(FileStream stream = File.Open(excelPath, FileMode.Open, FileAccess.Read)) { IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); excelReader.IsFirstRowAsColumnNames = true; DataSet result = excelReader.AsDataSet(); //Here split the datatable to two different sets and save it your database in two different tables. excelReader.Dispose(); }
bool checkempty = false; string holdcolumnname = ""; //Array.ForEach(Directory.GetFiles((Server.MapPath("~/admin/Import/"))), File.Delete); // Delete for all file in the Import Directory. //Array.ForEach(Directory.GetFiles((Server.MapPath("~/admin/Import/"))), ); // Delete for all file in the Import Directory. string path = string.Concat((Server.MapPath("~/admin/Import/" + productupload.FileName))); productupload.PostedFile.SaveAs(path); string temp = Path.GetExtension(path); comman = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0;"); //comman = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=YES;\";"); comman.Open(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", comman); conn.Open(); DbDataReader dr = cmd.ExecuteReader(); dt.Load(dr);
if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { holdValueInspectbyOrg1 = null; DataRow newRow = showResult.NewRow(); if (dt.Rows[i]["your column name paste here"].ToString().Trim() != null && dt.Rows[i]["Therapeutic Category Name"].ToString().Trim() != "") import.fk_TherapeuticCategoryID = dt.Rows[i]["Therapeutic Category Name"].ToString().Trim(); else { holdcolumnname = "Therapeutic Category name"; goto outer; } if (dt.Rows[i]["Company Name"].ToString() != null && dt.Rows[i]["Company Name"].ToString() != "") import.fk_ManufacturerIDs = dt.Rows[i]["Company Name"].ToString(); else { holdcolumnname = "Company Name"; goto outer; } if (dt.Rows[i]["Drug Generic Name"].ToString() != null && dt.Rows[i]["Drug Generic Name"].ToString() != "") import.INN = dt.Rows[i]["Drug Generic Name"].ToString(); else { holdcolumnname = "Drug Generic Name"; goto outer; }
Login to post response