private void InsertData() { //-- try { System.Data.OleDb.OleDbConnection MyConnection; System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand(); string sql = null; //string path = System.IO.Path.GetFullPath(Server.MapPath("~/InformationNew.xlsx")); string path = "D:/ttt.xlsx"; //MyConnection = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); string connstr= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/ttt.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=Yes;IMEX=1\""; MyConnection =new OleDbConnection(connstr); MyConnection.Open(); myCommand.Connection = MyConnection; //sql = "Insert into [Sheet1$] (id,name) values('5','e')"; sql = "Insert into [Sheet1$](a,b,c,d) Values('1','Vikas','Bohra','50')"; //sql = "Select * From [Sheet1$]"; myCommand.CommandText = sql; myCommand.CommandType = CommandType.Text; myCommand.ExecuteNonQuery(); MyConnection.Close(); } catch (Exception ex) { Response.Write(ex.ToString()); } //-- }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)