Wednesday, 4 August 2021

xls file data import to database using c#

 xls ( Excel sheet ) file data import to database using c#

string path = string.Concat(Server.MapPath("~/UploadFileFolder/" + FileUpload1.FileName));  

                    FileUpload1.SaveAs(path);  

                    string excel = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);  

                    using (OleDbConnection con = new OleDbConnection(excel))  

                    {  

                        OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]", con);  

                        con.Open();  

                        OleDbDataAdapter da = new OleDbDataAdapter(cmd);

                        DataSet ds = new DataSet();

                        da.Fill(ds);

                    }  

No comments:

Post a Comment