<pre lang="C#">OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.FileName = String.Empty; openFileDialog1.Filter = "All files (*.*)|*.*"; openFileDialog1.Title = "Select Your - Excel File :- "; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { String MyExcelFile = openFileDialog1.FileName; //Below For XLSX Format String StrConn2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + MyExcelFile + "; Extended Properties=\"Excel 12.0; HDR=YES; \""; String MyExcelSheet = "[Sheet1$]"; String MySQLSelect = "select * from " + MyExcelSheet; System.Data.OleDb.OleDbConnection Cn1 = new System.Data.OleDb.OleDbConnection(StrConn2); System.Data.OleDb.OleDbDataAdapter Da1 = new System.Data.OleDb.OleDbDataAdapter(MySQLSelect, Cn1); Cn1.Open(); Da1.Fill(MyContactsTbl); Cn1.Close(); Cn1.ReleaseObjectPool(); Cn1 = null; MessageBox.Show(MyExcelFile); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)